* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Retrieving part of a string (Axe)  (Read 341 times)

0 Members and 1 Guest are viewing this topic.

Offline Overreactedosbol

  • New User
  • Join Date: Nov 2016
  • Location:
  • Posts: 5
  • Post Rating Ratio: +0/-0
    • View Profile
Retrieving part of a string (Axe)
« on: November 16, 2016, 01:35:21 pm »
Hi there,

Recently I've been trying to find a way to select certain parts of a string to be used.
I know you can use StrABC + # to skip # letters, but here's what I need:

Imagine you have a string like this (This is an example, the real string I have is far longer):
"JOHNRODNEYKYLESIDNEYMICHAEL"->Str1NAME
how would I be able to retrieve a name out of it based on a key press and display it(for example "RODNEY" when I press 2nd)? Or could I in some way make a list of strings and do it that way?

PS: My knowledge of Axe is very basic, for example I've just wrapped my head around pointers.
Any help is appreciated and thanks in advance,

Overreacted  :)



Online p2

  • CodeWalrus Staff
  • Super User
  • Moderator
  • CodeWalrus Supporter
  • *
  • Join Date: Aug 2016
  • Location: Germany
  • Posts: 1873
  • Post Rating Ratio: +7/-0
  • *Wubba lubba dub dub*
    • KaliPhobos
    • View Profile
  • Gender: Male
Re: Retrieving part of a string (Axe)
« Reply #1 on: November 16, 2016, 01:57:11 pm »
Hey there Overreact, welcome to the forum  :thumbsup:

Here, have a walrus: :walrii:
How about you introduce yourself to the forum? :) http://codewalr.us/32/46328 I know that might seem bring but we all did it ;)

About your problem:
You have a string and two numbers (lets call them n and x)
And you want a method to get the next n letters from the string, starting on position x?
Or did I misunderstood you? :)

Also what axe version are you working with? :)
  • Calculators owned: ti-83+, ti-84+, ti-84+, ti-84+se, ti-84+se(te), ti-nsphire, ti-nsphire CX-CAS, ti-voyage, ti-voyage, Who reads this list anyways...?
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

Offline Overreactedosbol

  • New User
  • Join Date: Nov 2016
  • Location:
  • Posts: 5
  • Post Rating Ratio: +0/-0
    • View Profile
Re: Retrieving part of a string (Axe)
« Reply #2 on: November 16, 2016, 02:01:11 pm »
Yes, that's exactly what I need. I know I can store those numbers for each seperate name in a list of some sort, but how do I tell the string to take the next n letters? Because I know Str+x is how I get to the position.
I'm using Axe 1.2.2 btw

Offline ben_g

  • Full User
  • Safe-haven access
  • Join Date: Dec 2014
  • Location:
  • Posts: 159
  • Post Rating Ratio: +9/-0
    • View Profile
Re: Retrieving part of a string (Axe)
« Reply #3 on: November 16, 2016, 04:28:41 pm »
Code: [Select]
Lbl SubStr
.SubStr(str,begin,len)
Copy(r1+r2,L4,r3)
0->{r1+r2+r3}
Return L4
If you embed this code in your program, then you can call SubStr( (type this out yourself, there is no token for it) and it will return a fraction of the string supplied in the first argument, starting from the supplied begin index (0 is the start) and len chars long.
This code uses the Copy( command to copy the desired part of the string to the TempSwapArea (L4) (so if you use this for data storage you'll have to change it to another free RAM area) and adds a 0 byte at the end (to allow axe to see where the string ends). When using this code, make sure that the length is never bigger than 255 and that you never ask for a string with a length of 0 (both could cause a crash).

Example:
Code: [Select]
Text SubStr("JOHNRODNEYKYLESIDNEYMICHAEL",4,6)
This should draw the text "RODNEY" to the screen.

However if you just want to use it for a list of strings, then you might want to define your strings like this instead:
Code: [Select]
Data(Str000^r,Str001^r,Str002^r,Str003^r,Str004^r,Str005^r,Str006^r)->°SLIST
"JOHN"->Str000
"RODNEY"->Str001
"KYLE"->Str002
"SIDNEY"->Str003
"MICHAEL"->Str004
"BEN"->Str005
"JAKE"->Str006
When you define your strings like this, then you can get each string of the list by doing {I*2+°SLIST}^r where I is the index of the string you want (with 0 being the first string). This method works similar to how an array of strings works internally in higher level programming languages.

Example:
Code: [Select]
Text {2*2+°SLIST}^r
This should draw the text "KYLE".

EDIT: fixed incorrect code
« Last Edit: November 16, 2016, 04:43:41 pm by ben_g »

Offline Hayleia

  • Full User
  • Join Date: Nov 2014
  • Location:
  • Posts: 309
  • Post Rating Ratio: +10/-0
    • View Profile
Re: Retrieving part of a string (Axe)
« Reply #4 on: November 16, 2016, 07:43:16 pm »
Or just use strGet. See the Commands.html file for more info, but basically, put your strings one after the other separated with zeroes then use strGet to get a pointer to the Nth one.
Code: [Select]
[]->°TheStrings
"Yes"[00]
"No"[00]
"Toaster"[00]
"The Game"[00]
"Juju lost"[00]

Disp strGet(°TheStrings, 2)

Offline Overreactedosbol

  • New User
  • Join Date: Nov 2016
  • Location:
  • Posts: 5
  • Post Rating Ratio: +0/-0
    • View Profile
Re: Retrieving part of a string (Axe)
« Reply #5 on: November 16, 2016, 08:01:20 pm »
Thanks so much! That worked  ;D

Online p2

  • CodeWalrus Staff
  • Super User
  • Moderator
  • CodeWalrus Supporter
  • *
  • Join Date: Aug 2016
  • Location: Germany
  • Posts: 1873
  • Post Rating Ratio: +7/-0
  • *Wubba lubba dub dub*
    • KaliPhobos
    • View Profile
  • Gender: Male
Re: Retrieving part of a string (Axe)
« Reply #6 on: November 16, 2016, 08:06:43 pm »
wouldn't it be a great idea to collect all the questions and turn it into a huge FAQ for beginners...? Could be super usefull ^^

Also @Hayleia you should sometimes maximize the IRC <_<
I dont get it generally why you always minimize it ^^
* p2 pokes Hayleia
  • Calculators owned: ti-83+, ti-84+, ti-84+, ti-84+se, ti-84+se(te), ti-nsphire, ti-nsphire CX-CAS, ti-voyage, ti-voyage, Who reads this list anyways...?
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

Offline Overreactedosbol

  • New User
  • Join Date: Nov 2016
  • Location:
  • Posts: 5
  • Post Rating Ratio: +0/-0
    • View Profile
Re: Retrieving part of a string (Axe)
« Reply #7 on: November 16, 2016, 08:08:11 pm »
True, I find myself often scrolling through user topics to find answers to simple questions.

Offline E37

  • Full User
  • Join Date: Jul 2016
  • Location: Lihilzard Empire
  • Posts: 198
  • Post Rating Ratio: +9/-0
  • I own 2 game consoles, a ti-83 and a ti-84!
    • E37
    • View Profile
Re: Retrieving part of a string (Axe)
« Reply #8 on: November 16, 2016, 09:10:28 pm »
Welcome!
It is always nice to see beginning Axe programmer. You can always pm me with any questions, and I should be able to respond in under a day. (the personal messages are under the My Messages tab)

Hope you enjoy your stay!
  • Consoles, mobile devices and vintage computers owned: Ti83,Ti84!
I've never finished a project, there is always a way to improve!
What's my calc's name? Convert $37 to decimal. Look up that element in the periodic table. Then take the abbreviation of that element and you have it!
Look! A slime!    <(^.^)>

Offline c4ooo

  • ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  • Super User
  • CW Contest II Winner
  • *
  • Join Date: Aug 2015
  • Location: 127.0.0.1
  • Posts: 825
  • Post Rating Ratio: +7/-2
  • ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
    • View Profile
  • Gender: Male
Re: Retrieving part of a string (Axe)
« Reply #9 on: November 17, 2016, 01:15:21 am »
Or just use strGet. See the Commands.html file for more info, but basically, put your strings one after the other separated with zeroes then use strGet to get a pointer to the Nth one.
Code: [Select]
[]->°TheStrings
"Yes"[00]
"No"[00]
"Toaster"[00]
"The Game"[00]
"Juju lost"[00]

Disp strGet(°TheStrings, 2)
Best answer.
??? ??? ???

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games