Author Topic: Help parsing a string  (Read 5797 times)

0 Members and 1 Guest are viewing this topic.

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
Help parsing a string
« on: January 18, 2011, 05:37:08 pm »
Hai im back with another probably dumb question. So i have a users input stored to I, then the first letter of I is stored to N. I have "RLDQ" stored to C. Im trying to figure out how to step thru the letters in C and compare them to N. Inside a For( loop, i have this code:
Code: [Select]
If (N=(C+A)):Goto KK:End Where A increments from 1 to 4. It seems to always return false and i know it has to do with the If block. Help plz EDIT: i just realized that when i copy the first byte of I to N, it doesnt stay as a char. Oops
« Last Edit: January 18, 2011, 05:41:17 pm by DJ Omnimaga »

jnesselr

• King Graphmastur
• LV11 Super Veteran (Next: 3000)
• Posts: 2270
• Rating: +81/-20
• TAO == epic
Re: Help parsing a string
« Reply #1 on: January 18, 2011, 05:49:38 pm »
I would also do A from 0-3, not 1-4.  Also, {C+A} I believe would be more accurate as you are getting the byte at location C+A.

Runer112

• Project Author
• LV11 Super Veteran (Next: 3000)
• Posts: 2289
• Rating: +639/-31
Re: Help parsing a string
« Reply #2 on: January 18, 2011, 05:54:09 pm »
May I suggest a simpler soultion? inData(N,C) will return the 1-based position at which the byte stored in N is found in the string, or 0 if it is not found.
« Last Edit: January 18, 2011, 05:55:38 pm by Runer112 »

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
Re: Help parsing a string
« Reply #3 on: January 18, 2011, 05:59:55 pm »
Ok i cant seem to get the first byte of I as a character so ill try inData. Will report back in a sec. One sec later, I got this to work:
Code: [Select]
 For(A,0,3):If inData({C+A}, I):Goto KK:End:End Thatx guise! I didnt know about inData lol
« Last Edit: January 18, 2011, 06:07:42 pm by Broseph Radson »

AngelFish

• Is this my custom title?
• LV12 Extreme Poster (Next: 5000)
• Posts: 3242
• Rating: +270/-27
• I'm a Fishbot
Re: Help parsing a string
« Reply #4 on: January 18, 2011, 06:57:06 pm »
inData( would be better. Remember that you'll occasionally have problems with getting the characters to display properly, so set the byte with a known hex value to test it. Don't trust your input routine.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
Re: Help parsing a string
« Reply #5 on: January 18, 2011, 07:16:53 pm »
Ok another question. How to i get a substring? Like get the last part of a string?
Code: [Select]
For(A,3,Length([string]))//something to get the character at A and append it to another stringEndOr is there a command that does this?

Quigibo

• The Executioner
• CoT Emeritus
• LV11 Super Veteran (Next: 3000)
• Posts: 2031
• Rating: +1075/-24
Re: Help parsing a string
« Reply #6 on: January 18, 2011, 07:33:17 pm »
To get the end of the string you don't even need a command.  If your string is Str1, lets say it says: "Hello".  Then Str1+1 is "ello", Str1+2 is "llo", Str1+3 is "lo" etc.
___Axe_Parser___
Today the calculator, tomorrow the world!

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
Re: Help parsing a string
« Reply #7 on: January 18, 2011, 07:49:40 pm »
orly i didnt try that. ill try once i remake the program. Just got a RAM clear messing with interrupts lol. which reminds me i have a question about interrupts but ill make a new thread for that.
« Last Edit: January 18, 2011, 07:50:57 pm by Broseph Radson »

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
Re: Help parsing a string
« Reply #8 on: January 19, 2011, 08:52:15 pm »
Another question involving strings (since i cant for the life of me find the thread where this was mentioned), how do i insert a token at the beginning of a string? Like if R is "ABC" and i want to make it say "prgmABC"

Deep Toaster

• So much to do, so much time, so little motivation
• LV13 Extreme Addict (Next: 9001)
• Posts: 8206
• Rating: +758/-15
Re: Help parsing a string
« Reply #9 on: January 19, 2011, 09:06:44 pm »
The easiest Axe way to do it would be to make a new string and copy it over.

If you want a faster way to do it, there's bcall(_InsertMem), which allocates extra memory for a variable.

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
Re: Help parsing a string
« Reply #10 on: January 19, 2011, 09:26:48 pm »
ok that worked but the token is copying as a character. How do i copy a token? It gives me a bad symbol error when i do >Tok in the copy and when i try to store it to its own string

Deep Toaster

• So much to do, so much time, so little motivation
• LV13 Extreme Addict (Next: 9001)
• Posts: 8206
• Rating: +758/-15
Re: Help parsing a string
« Reply #11 on: January 19, 2011, 11:02:31 pm »
Use T. For example, Tprgm→{getCalc("Str0")}.

Another question involving strings (since i cant for the life of me find the thread where this was mentioned), how do i insert a token at the beginning of a string? Like if R is "ABC" and i want to make it say "prgmABC"

How can R be a string?

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
Re: Help parsing a string
« Reply #12 on: January 19, 2011, 11:16:45 pm »
Good question but it works for me. I cant store input to a regular string var so idk. I forgot about that T thing thanks. The most recent version of the commands list i have printed (no computer access) is 0.4.1 so i guess it wasnt listed in that one

Deep Toaster

• So much to do, so much time, so little motivation
• LV13 Extreme Addict (Next: 9001)
• Posts: 8206
• Rating: +758/-15
Re: Help parsing a string
« Reply #13 on: January 19, 2011, 11:17:46 pm »
DJ posted an online version here.

• Posts: 295
• Rating: +20/-1
• Its 0x1A4 somewhere
Re: Help parsing a string
« Reply #14 on: January 20, 2011, 10:33:52 pm »
well i tried copying the prgm token to the string then copying the progname to the string after the prgm token, but when i display it it spits out garbage. im sorry i know i really suck at this