TLex string parsing
| Thu, 2005-09-15 09:47 | |
|
Hey All,
  I'm trying to parse a space delimited string with several tokens in it and have had no luck. Every time I do a NextToken() I simply get the previous string, but with the front chopped off. Is this correct? Here's a bit of code to illustrate: _LIT(KStringToParse, "One Two Three Four Five"); TLex lex(KStringToParse); TPtrC one = lex.NextToken(); // Expecting: one = "One" Actually: one = "One Two Three Four Five"; TPtrC two = lex.NextToken(); // Expecting: two = "Two" Actually: two = "Two Three Four Five"; TPtrC three = lex.NextToken(); // Expecting: three = "Three" Actually: three = "Three Four Five"; TPtrC four = lex.NextToken(); // Expecting: four = "Four" Actually: four = "Four Five"; TPtrC five = lex.NextToken(); // Expecting: five = "Five" Actually: five = "Five"; I just wanna grab one token at a time and use them as I would a TDesC. Any ideas? Thanks,   scarab |
|






Forum posts: 5
Thanks,
Scarab
Forum posts: 672
TPtrC one = lex.NextToken();
// one = "One Two Three Four Five";
TInt nextSpacePos = one.Locate(KSpace);
// nextSpacePos =3
TPtrC first = one.Left(nextSpacePos);
// first = "One"
TPtrC two = lex.NextToken();
// two = "Two Three Four Five
nextSpacePos = two.Locate(KSpace);
TPtrC second =two.Left(nextSpacePos);
etc. Would this do?
Forum posts: 5
Something like that should work. I get compilation errors, however, on
TInt nextSpacePos = one.Locate(KSpace);
and when I switch it up to to
TInt nextSpacePos = one.Locate(' ');
it compiles fine, but nextSpacePos = -1 after that line executes. If I switch it to
TInt nextSpacePos = one.Locate('e'); // nextSpacePos = 2 for _LIT(KStringToParse, "One Two Three Four Five");
I get a valid value. How come it won't find spaces? Do I need to escape the space character with something? I also tried
TInt nextSpacePos = one.Locate(TChar(32)); //ASCII code for space
to no avail as well. What's going on?!
- scarab
Forum posts: 9
change it to TInt nextSpacePos = token.Find(_L(" "));
--------------------
Roy Weinberg,
Symbian Development Manager,
SBSH Mobile Software.