Author Topic: Display one character of a string?  (Read 4416 times)

0 Members and 1 Guest are viewing this topic.

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Display one character of a string?
« 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?

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Display one character of a string?
« Reply #1 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.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Display one character of a string?
« Reply #2 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!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Display one character of a string?
« Reply #3 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.)




Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Re: Display one character of a string?
« Reply #4 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}?

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Display one character of a string?
« Reply #5 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)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Display one character of a string?
« Reply #6 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.




Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Display one character of a string?
« Reply #7 on: March 30, 2012, 04:55:34 pm »
Or, a much simpler and prettier way:

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

 ;)

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Re: Display one character of a string?
« Reply #8 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.