Jump to content
Sign in to follow this  
ColonelSandersLite

Converting Strings

Recommended Posts

Another version:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

/*

   Based on Vova _Fox version.

   "string" call compile preprocessfile "str2arr\str2arr1.sqf"

   "st""wqerr_!@#$@#$ASDring" call compile preprocessfile "str2arr\str2arr1.sqf"

*/

private ["_prev", "_char", "_bigstr", "_chars", "_substr", "_padding", "_array"];

_chars = [

   " ","!","""","#","$","%","&","'","(",")","*","+",",","-",".","/",

   "0","1","2","3","4","5","6","7","8","9",

   ":",";","<","=",">","?","@",

   "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",

   "[","\","]","^","_","`",

   "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",

   "{","|","}","~",""

];

_bigstr = " ";

_padding = "";

_array = [];

_prev = "";

// _bigstr length == 2048

for "" from 0 to 10 do { _bigstr = _bigstr + _bigstr };

for "" from 0 to 2045 do {

   _padding = _padding + " ";

   _substr = call compile (format["%1'%2", call compile (format["%1'%2", _padding, _bigstr] + "'"), _this] + "'");

   if( isnil "_substr" )exitWith{};

   if( _prev == _substr )exitWith{};

   _char = { if( _substr in [_prev+_x] )exitWith{ _x }; "" } foreach _chars;

   _array set [count _array, _char];

   _prev = _substr;

};

_array

Share this post


Link to post
Share on other sites

It looks like 1.09 will contains some new string manipulation commands: toArray, toString, toUpper and toLower.

toArray outputs ascii character codes rather than characters, which is a bit odd.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

/*

   Based on Vova _Fox version.

   "string" call compile preprocessfile "str2arr\str2arr_bin.sqf"

   "str[]"" ""@#$$ QWERing" call compile preprocessfile "str2arr\str2arr_bin.sqf"

   "str[]"" ""@ASDF  : = + ) ( [ ]#$$ QWERing" call compile preprocessfile "str2arr\str2arr_bin.sqf"

*/

private ["_strs", "_array", "_prev", "_padding", "_char", "_chars", "_substr"];

_chars = [

   " ","!","""","#","$","%","&","'","(",")","*","+",",","-",".","/",

   "0","1","2","3","4","5","6","7","8","9",

   ":",";","<","=",">","?","@",

   "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",

   "[","\","]","^","_","`",

   "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",

   "{","|","}","~",""

];

_strs = [" "];

for "_i" from 0 to 10 do {

   _prev = _strs select _i;

   _strs set [count _strs, _prev + _prev]

};

_array = [];

_prev = "";

for "_i" from 2045 to 0 step -1 do {

   _padding = "";

   for "_j" from 0 to 10 do {

       if( floor( ( _i/(2^_j) ) % 2 ) == 1 )then{

           _padding = _padding + (_strs select _j)

       }

   };

   _substr = call compile (format["%1'%2", _padding, _this] + "'");

   if( isnil "_substr" )exitWith{};

   if( _prev == _substr )exitWith{};

   _char = { if( _substr in [_prev+_x] )exitWith{ _x }; "" } foreach _chars;

   _array set [count _array, _char];

   _prev = _substr;

};

_array

Share this post


Link to post
Share on other sites
It looks like 1.09 will contains some new string manipulation commands: toArray, toString, toUpper and toLower.

toArray outputs ascii character codes rather than characters, which is a bit odd.

Thanks for BIS those functions can be make easier and code should be faster.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×