Join us on Discord!
You can help CodeWalrus stay online by donating here.

Retrieving part of a string (Axe)

Started by Overreactedosbol, November 16, 2016, 01:35:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Overreactedosbol

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  :)

p2

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 CAS, 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)

Overreactedosbol

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

ben_g

#3

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:

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:

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:

Text {2*2+°SLIST}^r

This should draw the text "KYLE".

EDIT: fixed incorrect code

Hayleia

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.

[]->°TheStrings
"Yes"[00]
"No"[00]
"Toaster"[00]
"The Game"[00]
"Juju lost"[00]

Disp strGet(°TheStrings, 2)

Overreactedosbol


p2

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 CAS, 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)

Overreactedosbol

True, I find myself often scrolling through user topics to find answers to simple questions.

E37

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!    <(^.^)>

c4ooo

Quote from: Hayleia 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.

[]->°TheStrings
"Yes"[00]
"No"[00]
"Toaster"[00]
"The Game"[00]
"Juju lost"[00]

Disp strGet(°TheStrings, 2)

Best answer.

Powered by EzPortal