stringfield question.

Just starting out? Need help? Post your questions and find answers here.
noxidderf
User
User
Posts: 18
Joined: Thu Oct 03, 2024 5:31 pm

stringfield question.

Post by noxidderf »

i have this string.

mystring = ButtonGadget(#Button_0, 20, 30, 100, 25, "Button 0")

i want to split it up.
first i use stringfield(mystring, 1,"(") and i get what i expect "ButtonGadget("

> next instruction is stringfield(mystring, 1,",") and i get this "ButtonGadget(#Button_0" <

next instruction is stringfield(mystring, 2,",") and i get "20"
next instruction is stringfield(mystring, 2,",") and i get "30"
next instruction is stringfield(mystring, 2,",") and i get "100"
next instruction is stringfield(mystring, 2,",") and i get "25"

the line between > < is confusing me, or maybe it is the lines after.
what i men is the last 4 lines seem to be "pop" off the front of the line except for the line with > <
does the function return only what is between the delimiters?
this first line is between the start and the delimiter, [buttongadget]
the next line also is between the start and the delimiter [ButtonGadget(#Button_0"]
the rest are all between the delimiter of "," and are given as is.

is this right? I was pretty confused until i started to explain it. I am still a little unsure.
actual procedure is below. I am still new so it looks pretty rough.


Code: Select all

Procedure processLoc(List thisList.s())
   
   localtemp.s = LTrim(thislist.s())
   Debug localtemp.s 
   
   localtemp1.s = LTrim(StringField(localtemp.s, 1 ,"#"))
   Debug localtemp1.s 
   
   localtemp2.s = LTrim(StringField(localtemp.s, 1 ,","))
   Debug localtemp2.s 
   
   localtemp3.s = LTrim(StringField(localtemp.s, 2 ,","))
   Debug localtemp3.s
   
   localtemp4.s = LTrim(StringField(localtemp.s, 3 ,","))
   Debug localtemp4.s
   
   localtemp5.s = LTrim(StringField(localtemp.s, 4 ,","))
   Debug localtemp5.s
   
   localtemp6.s = LTrim(StringField(localtemp.s, 5 ,","))
   Debug localtemp6.s 
   
   ; ButtonGadget(#Button_0, 20, 30, 100, 25, "Button 0")
   
EndProcedure

goodnight, past my bed time.
Fred
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: stringfield question.

Post by TI-994A »

Try it this way:

Code: Select all

Procedure processLoc(List thisList.s())
  
  localtemp.s = Trim(thislist())
  Debug localtemp
  
  localtemp1.s = RTrim(StringField(localtemp, 1 ,"#"), "(")
  Debug localtemp1
  
  localtemp2.s = Mid(Trim(StringField(localtemp, 1 ,",")), Len(localtemp1) + 2)
  Debug localtemp2
  
  localtemp3.s = Trim(StringField(localtemp, 2 ,","))
  Debug localtemp3
  
  localtemp4.s = Trim(StringField(localtemp, 3 ,","))
  Debug localtemp4
  
  localtemp5.s = Trim(StringField(localtemp, 4 ,","))
  Debug localtemp5
  
  localtemp6.s = Trim(StringField(localtemp, 5 ,","))
  Debug localtemp6
  
  localtemp7.s = RTrim(StringField(localtemp, 6 ,","), ")")
  Debug localtemp7
  
EndProcedure

NewList myList.s()
AddElement(myList())
myList() = "ButtonGadget(#Button_0, 20, 30, 100, 25," + #DQUOTE$ + "Button 0" + #DQUOTE$ + ")"

processLoc(myList())
Image

Image
Last edited by TI-994A on Sat Oct 12, 2024 1:31 pm, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: stringfield question.

Post by infratec »

Slightly modified to get the values completely:

Code: Select all

Procedure processLoc(List thisList.s())
  
  localtemp.s = LTrim(thislist.s())
  Debug localtemp
  
  localtemp1.s = LTrim(StringField(localtemp.s, 1 ,"("))
  Debug localtemp1
  
  localtemp.s = StringField(localtemp.s, 2 ,"(")
  localtemp = RTrim(localtemp, ")")
  
  localtemp2.s = LTrim(StringField(localtemp.s, 1 ,","))
  Debug localtemp2
  
  localtemp3.s = LTrim(StringField(localtemp.s, 2 ,","))
  Debug localtemp3
  
  localtemp4.s = LTrim(StringField(localtemp.s, 3 ,","))
  Debug localtemp4
  
  localtemp5.s = LTrim(StringField(localtemp.s, 4 ,","))
  Debug localtemp5
  
  localtemp6.s = LTrim(StringField(localtemp.s, 5 ,","))
  Debug localtemp6
  
  localtemp7.s = LTrim(StringField(localtemp.s, 6 ,","))
  Debug localtemp7
  
EndProcedure

NewList myList.s()
AddElement(myList())
myList() = "ButtonGadget(#Button_0, 20, 30, 100, 25," + #DQUOTE$ + "Button 0" + #DQUOTE$ + ")"

processLoc(myList())
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: stringfield question.

Post by TI-994A »

infratec wrote: Sat Oct 12, 2024 1:29 pmSlightly modified to get the values completely...

Yes; you're right! And I'd substituted the relevant trim functions as well.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: stringfield question.

Post by mk-soft »

Resolving parameters can be somewhat time-consuming. Especially for strings with commas, or parameters with function calls.

See Link and function SplitParameterArray
SplitString and more ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
noxidderf
User
User
Posts: 18
Joined: Thu Oct 03, 2024 5:31 pm

Re: stringfield question.

Post by noxidderf »

thanks for thee nice graphics and the example.

if my idea works i would only need to run this once when i change the source.
how much slower is the stringfield functions suggested? just rough idea.


Feeling a little under the weather all of saterday, I just wanted to say a quick thanks.
Post Reply