Page 1 of 1

stringfield question.

Posted: Sat Oct 12, 2024 5:58 am
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

Re: stringfield question.

Posted: Sat Oct 12, 2024 7:12 am
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

Re: stringfield question.

Posted: Sat Oct 12, 2024 1:29 pm
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())

Re: stringfield question.

Posted: Sat Oct 12, 2024 1:33 pm
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.

Re: stringfield question.

Posted: Sat Oct 12, 2024 3:48 pm
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 ...

Re: stringfield question.

Posted: Sun Oct 13, 2024 2:45 am
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.