Page 1 of 2
String/Substring variable length [Solved]
Posted: Mon Aug 31, 2015 2:48 pm
by antrax13
Hi all,
I am not sure if this is the proper way of doing it but what I need is following.
I have values like:
and what I need is to get:
Is there any function that will remove last character from string or do I have to find out that length of string and then select char 1 to totalLength-1?
Regards
Re: String/Substring variable length
Posted: Mon Aug 31, 2015 3:15 pm
by Klaus
Hi antrax13,
no special function for this!
Use a repaet loop like this:
Code: Select all
...
## repeat for each.. is insanely fast, but read-only, so we fill a new variable here:
repeat for each line tLine in YourListHere
## Only use first to last - 1 character,
## luckily we can count from "backwards" in Livecode
put char 1 to -2 of tLine & CR after tNewList
end repeat
## Delete trailing CR
delete char -1 of tNewList
## Now do whatever you need to do with tNewList :D
...
Best
Klaus
Re: String/Substring variable length
Posted: Mon Aug 31, 2015 3:16 pm
by zaxos
How about that:
Code: Select all
Repeat with x = 1 to the number of lines of myvar
Delete last char of line x in myvar
End repeat
Re: String/Substring variable length
Posted: Mon Aug 31, 2015 3:28 pm
by antrax13
Klaus wrote:Hi antrax13,
no special function for this!
Use a repaet loop like this:
Code: Select all
...
## repeat for each.. is insanely fast, but read-only, so we fill a new variable here:
repeat for each line tLine in YourListHere
## Only use first to last - 1 character,
## luckily we can count from "backwards" in Livecode
put char 1 to -2 of tLine & CR after tNewList
end repeat
## Delete trailing CR
delete char -1 of tNewList
## Now do whatever you need to do with tNewList :D
...
Best
Klaus
Would your approach be faster than mine?
Code: Select all
put char 1 to ( the length of tField-1) of tField into withoutNumber
Re: String/Substring variable length
Posted: Mon Aug 31, 2015 3:42 pm
by Klaus
antrax13 wrote:Would your approach be faster than mine?
I have no idea!

Re: String/Substring variable length
Posted: Mon Aug 31, 2015 3:45 pm
by dunbarx
I would have predicted this.
With a sample of 1,000,000 lines, and a "repeat for each" loop with the variable tLine:
delete the last char of tLine = 11 ticks
delete char -1 of tLine = 13 ticks
put char 1 to the length of tLine - 1 of tLine = 14 ticks
Craig Newman
Re: String/Substring variable length
Posted: Mon Aug 31, 2015 3:46 pm
by zaxos
Its funny how I always get ignored over the moderators, embrace the power ppl, embrace the power.
Re: String/Substring variable length
Posted: Mon Aug 31, 2015 3:50 pm
by dunbarx
Zaxos.
What did you mean, "ignored".
I used your example as one of the timed tests. Though I made all loops the "repeat for" style, as opposed to "repeat with".
Craig
Re: String/Substring variable length
Posted: Mon Aug 31, 2015 3:55 pm
by zaxos
Not talking about you dunbarx, nor for any moderator, I think its obvious who this goes about, thank you for your tests tho

Re: String/Substring variable length
Posted: Mon Aug 31, 2015 4:51 pm
by antrax13
Thanks all.
Special thank you for
zaxos 
Re: String/Substring variable length [Solved]
Posted: Mon Aug 31, 2015 4:52 pm
by Klaus
Hi zaxos,
you are "speaking in tongues"!
Best
Klaus
Re: String/Substring variable length [Solved]
Posted: Mon Aug 31, 2015 6:03 pm
by zaxos
antrax13:
Thanks all.
Special thank you for zaxos

Thank you for thanking me! thats all i needed
Kalus:
Hi zaxos,
you are "speaking in tongues"!
Best
Klaus
I had to google that since i'm not familar with that expression, wiki came up with:
Glossolalia or (speaking in tongues) is the fluid vocalizing of speech-like syllables that lack any readily comprehended meaning, in some cases as part of religious practice. Some consider it as a part of a sacred language. It is a common practice amongst Pentecostal and Charismatic Christianity.
I still dont understand what that means! I'm not even sure if i should be offended

, i do know thought that my text in not always easily understandable if thats what you mean, if on the other hand you mean that my words are meaningless then my answer to that is that we are not robots, people can and should be polite, it costs nothing, so stop being so judgmental and help me out here.
Craig, could you share with me how you tested this? thank you

Re: String/Substring variable length [Solved]
Posted: Mon Aug 31, 2015 7:37 pm
by zaxos
Craig? i thought it is "put the milliseconds" at the end of the handler but this gives me 1441046154985... I guess thats a bit too much.
nvm. the code below gave me 13 ticks, so i guess it worked
Code: Select all
on mouseUp
local theVar
local tTime
put the ticks into tTime
repeat 1000000
put "test" into theVar
end repeat
put the ticks-tTime
end mouseUp
Re: String/Substring variable length [Solved]
Posted: Mon Aug 31, 2015 8:32 pm
by Klaus
Hi zaxos,
zaxos wrote:I still dont understand what that means! I'm not even sure if i should be offended

, i do know thought that my text in not always easily understandable if thats what you mean,
no offence!
I just meant: The meaning of your talking is mysterious!

I other words, I have no idea what you mean with:
Not talking about you dunbarx, nor for any moderator, I think its obvious who this goes about...
Best
Klaus
Re: String/Substring variable length [Solved]
Posted: Mon Aug 31, 2015 9:11 pm
by zaxos
I see, so maybe i was unclear
This was obviously meant for dunbarx:
Not talking about you dunbarx
Now this was actualy for you:
nor for any moderator
unless i'm wrong, you are a moderator of this forum(?)
And the last part of which i thought was obvious was meant for antrax13 who was kind enough to saw me i was wrong at the end:
I think its obvious who this goes about...