Game Development Community

Replace acharacter with space

by Nir Ziso · in Torque Game Builder · 08/02/2006 (10:06 am) · 5 replies

Hoe can i use the strreplace function to replace agiven string with space
how can i pass the function space character i did this but it is not working

function mystr::read_string(%this,%str,%delimiter)
{
echo("_______________________________________________");
echo("str="SPC %str);
echo("delimiter="SPC %delimiter);
%temp=strreplace(%str, %delimiter,SPC );
echo("new string="SPC %temp);
}

#1
08/02/2006 (11:23 am)
Function mystr::read_string(%this,%str,%delimiter)
{
echo("_______________________________________________");
echo("str="SPC %str);
echo("delimiter="SPC %delimiter);
%temp=strreplace(%str, %delimiter, " ");
echo("new string="SPC %temp);
}

That should work I think, but I haven't tested it...
#2
08/02/2006 (11:25 am)
Use a string that only consists of a space: " "

SPC is just an operator that concatenates 2 strings.
#3
08/02/2006 (11:58 am)
Thanks alot i found it and here is my code to read asring with delimiter and put the values on an array
function mystr::read_string(%this,%str,%delimiter)
{
%wrapper = new ScriptObject();
echo("_______________________________________________");
echo("str="SPC %str);
echo("delimiter="SPC %delimiter);
%k=" ";
%temp=strreplace(%str, %delimiter,%k);
echo("new string with space="SPC %temp);
echo("string length with spaces="SPC strlen(%temp)) ;
echo("number of spaces"SPC getWordCount(%temp));
%counter=getWordCount(%temp);
for(%i=0;%i<%counter;%i++)
{
%msg=getWord(%temp,%i);
echo("msg="SPC %msg);
%wrapper.contents[%i]=%msg;
}
for(%i=0;%i<%counter;%i++)
echo("this is the array"SPC %wrapper.contents[%i]);
}
#4
08/02/2006 (1:28 pm)
Take a look at this. It will enable you to put your code into neat little gray code boxes.