You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

Retrieving part of a string (Axe)

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

0
b/Calculator Talk publicado por u/Overreactedosbol 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  :)
Inicia sesión o crea una cuenta para dejar un comentario
u/p2 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? :)
u/Overreactedosbol 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
u/ben_g November 16, 2016, 04:28:41 PM

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
Last Edit: November 16, 2016, 04:43:41 PM by ben_g
u/Hayleia 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)
u/Overreactedosbol November 16, 2016, 08:01:20 PM
Thanks so much! That worked  ;D
u/p2 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
u/Overreactedosbol November 16, 2016, 08:08:11 PM
True, I find myself often scrolling through user topics to find answers to simple questions.
u/E37 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!
u/c4ooo November 17, 2016, 01:15:21 AM
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.
Start a Discussion

b/Calculator Talk

Saw a cool TI, HP or Casio program out there? Need help programming or installing a software? This place is for you.

283
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal