Game Development Community

Need help with Torque Really confused

by frostwind · in Torque 3D Beginner · 09/23/2013 (2:41 pm) · 1 replies

Ok, what would i do if i wanted to replace a whole lot of words with one character, like if i would do,

test(this is a sentance);

and it would return as

**** ** * ********

I am stuck and dont know what to do right now.
Thanks!

#1
09/23/2013 (3:01 pm)
function test(%text, %replace)
{
   %len = strLen(%text);
   %result = "";
   for (%i = 0; %i < %len; %i ++)
   {
       if (getSubStr(%text, %i, 1) $= " ") 
          %result = %result @ " ";
       else
          %result = %result @ %replace;  
   }
   return %result;
}

test("this is a sentence", "*");

untested but should work