Problem with the string function mid()
Displaying 1-5 of 5 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Technetium

I am working on my Japanese language library. I have a string stored that is '#hir su go i'. I need to be able to analyze each character in the string. I have a variable to define which character in the string I am currently reading: curchar. I want to be able to read any character in the string depending on what this variable is set at, so for now I am using:
[pre]mid(input,curchar,curchar)[/pre]
However, this always returns an empty string. I guess mid does not work with both values being the same? I thought about trying, as an alternative:
[pre]left(mid(input,curchar,curchar+1),1)[/pre]
But I am pretty sure this will cause a problem when I get to the end of the string, and curchar+1 does not exist.

Any suggestions?

Posted on 2005-07-12 12:32:14

Technetium

Hm, it is not letting me edit my post. Something about a fatal error. Anyway, I guess I am too used to VBulletin code. The code parts should read:
mid(input,curchar,curchar)

and
left(mid(input,curchar,curchar+1),1)

Posted on 2005-07-12 12:34:16

Overkill

You won't run into problems, I don't think. If the upper range exceeds the string boundary it probably will just return the last character.

Posted on 2005-07-12 12:55:31

Technetium

Well, that didn't work either (returned a blank string). However, nesting right() within left() worked fine. Something's funky about that mid() function...

Posted on 2005-07-12 14:20:28

Gayo

The third parameter of mid() isn't the end coordinate, it's the length of the string taken. So to take just the n-position char (starting at 0), you'd do mid(mystring, n, 1). Thus, a loop to run through each char of a string one at a time would be:


for (position = 0; position < len(mystring); position++)
{
curchar = mid(mystring, position, 1);
}

Posted on 2005-07-12 15:01:43


Displaying 1-5 of 5 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.