Omnimaga

Calculator Community => Major Community Projects => The Axe Parser Project => Topic started by: BlakPilar on March 30, 2012, 08:28:15 am

Title: Display one character of a string?
Post by: BlakPilar on March 30, 2012, 08:28:15 am
I know that I can display every character after a certain position by doing something like Str1+N, but how can I only get the character at N?
Title: Re: Display one character of a string?
Post by: Matrefeytontias on March 30, 2012, 09:40:33 am
You can use the brackets : {Str1+N}. It'll display only the Nth character of the string.
Title: Re: Display one character of a string?
Post by: ztrumpet on March 30, 2012, 11:39:21 am
Here's how I'd do it:
{Str1+N}->A
Disp oA

This is how it works:
The first line stores the number of the character into the first byte of a two byte variable.  Since the upper 8 bits are all zero, a zero is stored with the number as well.  So the two bytes of variable A look like N, 0.
The second line just displays the character.  To do so, you need the address of a, which is what the degrees symbol gives you.

I hope this helps!
Title: Re: Display one character of a string?
Post by: Deep Toaster on March 30, 2012, 11:48:52 am
You could also do Disp {N+Str1}►Char.

(N+Str1 is much more optimized than Str1+N, by the way.)
Title: Re: Display one character of a string?
Post by: BlakPilar on March 30, 2012, 02:58:00 pm
Ahh, okay, thanks guys. Does that also mean that if I wanted to store the quote character to a string, I could do something like E22->{N+Str1}?
Title: Re: Display one character of a string?
Post by: Matrefeytontias on March 30, 2012, 03:52:51 pm
Yeah, it works ! If you type it :
Code: [Select]
:"ABCDE"->Str1
:E22->{Str1+2
:Disp Str1
You'll get AB"DE (tested)
Title: Re: Display one character of a string?
Post by: Deep Toaster on March 30, 2012, 04:47:52 pm
You could also do
:[]→Str1
:"AB"
:[22]
:"DE"
:[00]
:Disp Str1
That way the quote character is compiled into the string, so you don't have to waste time and RAM to put it in when the program's running.
Title: Re: Display one character of a string?
Post by: Runer112 on March 30, 2012, 04:55:34 pm
Or, a much simpler and prettier way:

:"AB"[22]"DE"→Str1

 ;)
Title: Re: Display one character of a string?
Post by: BlakPilar on March 30, 2012, 05:43:27 pm
Again, thanks guys! I figured it'd be something simple like that. I never really understood the need for pointers, but after the last week or so of testing, I do.