Period/Fullstop in Text Parser? (SOLVED)

Started by Candall, Mon 26/11/2007 02:09:17

Previous topic - Next topic

Candall

I've been attempting to implement a function in which my player character can inquire about a computer file (complete with extension) by way of the text parser.

When I enter the word in the parser list as "filename.ext" I get problems.  The code works perfectly if I simply use "filename".

I'm certain that I'm updating both the parser list and the calling function.

So is the problem that periods can't be used as regular characters in the text parser?  If so, is there a known workaround?

frission

#1
The easiest workaround would be to just turn the periods into something else before running ParseText, e.g.

while (inputText.Contains(".")!=-1) {
    inputText.ReplaceCharAt(inputText.Contains("."),"_");
}
Parser.ParserText(inputText);

And then just make sure that instead of "filename.ext", your parser list contains names like "filename_ext" or whatever. (And if "_" doesn't work for some reason, change it to something else).

Khris

ReplaceCharAt has to be called with a char as second parameter, so use '_' instead.

Candall

#3
Thanks!  It worked beautifully after a couple of minor repairs, one of which KhrisMUC pointed out.  Here's the code I ended up using after consulting the manual on the great direction in which you pointed me:

Code: ags
while (ech.Contains(".")!=-1){
 ech=ech.ReplaceCharAt(ech.Contains("."), '-');
}


As said, that works perfectly.  I posted it for the benefit of anyone who may run into this problem in the future.

Edit to add:  It turns out that the only "special" character I could find that didn't cause problems was a hyphen, though it really didn't matter whether the character was special or not so long as the altered string matched what was in the parser list.

SMF spam blocked by CleanTalk