1
Technical forum / Some string problems
« on: July 28, 2005, 06:32:20 PM »
I have a function that parses a string. It searches for a token and then returns the string from the beginning to that token.
basicly it looks like this (token is "@"):
When i run this function in a loop like this it crashes whole program on second loop pass:
These functions assume that srcString always begins and ends with a token (i have checked if wrong token position causes the crash or trying to reach out of bounds of the string but everythin is OK for that matter).
I think there is something about string assignment. How does WME handle "str=str2" command? does it simply copy the whole object (str2 into str) or does it try to fit str2 data into str? I have a feeling it's memmory assignment problem.
basicly it looks like this (token is "@"):
Code: [Select]
function getFirst( input )
{
return input.Substring(1,input.IndexOf("@",1)-1);
}
When i run this function in a loop like this it crashes whole program on second loop pass:
Code: [Select]
function ParseDialogueString(srcString)
{
var first=new String(2024);
var str=new String(srcString);
while (str.Length>1)
{
first = getFirst(str);
str = cutFirst(str);
// BLAH BLAH REST OF THE CODE
}
}
cutFirst cuts the first part of the string (right to the token), the function is almost the same as GetFirst.These functions assume that srcString always begins and ends with a token (i have checked if wrong token position causes the crash or trying to reach out of bounds of the string but everythin is OK for that matter).
I think there is something about string assignment. How does WME handle "str=str2" command? does it simply copy the whole object (str2 into str) or does it try to fit str2 data into str? I have a feeling it's memmory assignment problem.