Is there an easier way to trim a string?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Is there an easier way to trim a string?
The only solution I can find is rather
long-winded.
Simpler code if you can.
http://snipurl.com/20l7i [www_wikifortio_com]
long-winded.
Simpler code if you can.
http://snipurl.com/20l7i [www_wikifortio_com]
Life is just a bowl of cherries.
Re: Is there an easier way to trim a string?
As most of your efforts so farbjb007 wrote:The only solution I can find is rather
long-winded.
...

Could you please simply post your code and tell us what you want to achieve next time?
I do not think many people take the time to load your tiny stacks and gues from the scripts what you actually want to do!
OK, maybe this is what you want?
HINT! Please get used to QUOTE names of objects!
Code: Select all
on mouseUp
put field "lblTrimString" into theString
delete item -1 of theString
put theString & "," into fld "lblTrimString"
end mouseUp
Best
Klaus
P.S.
You should try to stop thinking too complicated!
Don't think C or C++ or whatever!
Think ENGLISH!
Try to tell yourself/wife/girlfirend/buddy/dog/cat what you want to do in english and then you can translate that almost 1:1 into Rev most of the time!
You'd be surprised how often I get questions like:
"Hi! I want to delete the last item of a field, but then the comma is also deleted so I want to put a comma after that field!"
while the answer is in the question:
Code:
delete last item of field "Quoted Name"
put comma after field "Quoted Name"
All it requires is structured thinking.
Best,
Mark
"Hi! I want to delete the last item of a field, but then the comma is also deleted so I want to put a comma after that field!"
while the answer is in the question:
Code:
delete last item of field "Quoted Name"
put comma after field "Quoted Name"
All it requires is structured thinking.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Or how about this one-liner?
And slightly more verbose, if you don't like the negative item number syntax
Jan Schenkel.
Code: Select all
put empty into item -1 of x
Code: Select all
put empty into the last item of x
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Hi Jan,
That's less natural language style and you lose a comma at the end. Surely, the experienced and efficient xTalk programmer does it that way.
Best,
Mark
That's less natural language style and you lose a comma at the end. Surely, the experienced and efficient xTalk programmer does it that way.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Is there an easier way to trim a string?
Thanks you all for your suggestions
Yes, it is "thinking reform" that I
need and I'm sure I'll get there in
the end.
Klaus: I find that the best way to get
an answer to a coding problem is to
use a separate script. Posting a bit
of code is more difficult since it's
in a script with different vars etc.
Also think it might be useful to other
learners to have something they can
run "out of the box" rather than trying
to figure out what to do with snippets
they find here.
I beg your indulgence as a nearly-71 year-old
just back from the cardiac ward - with my
"Grump" factor greatly increased.
Yes, it is "thinking reform" that I
need and I'm sure I'll get there in
the end.
Klaus: I find that the best way to get
an answer to a coding problem is to
use a separate script. Posting a bit
of code is more difficult since it's
in a script with different vars etc.
Also think it might be useful to other
learners to have something they can
run "out of the box" rather than trying
to figure out what to do with snippets
they find here.
I beg your indulgence as a nearly-71 year-old
just back from the cardiac ward - with my
"Grump" factor greatly increased.
Life is just a bowl of cherries.
Is there an easier way to trim a string?
Done some testing with the ideas offered.
They all suffer from the same fault - OK for
one "Trim" but don't work for repeated
trims.
Perhaps anyone with further suggestions
would like to download the file and test
before posting.
They all suffer from the same fault - OK for
one "Trim" but don't work for repeated
trims.
Perhaps anyone with further suggestions
would like to download the file and test
before posting.
Life is just a bowl of cherries.
I don't want to. You demand, but don't even want to tell us what the problem is, nor what solution you'd like, nor what the code is you tried up to now. If you can't even give that, I won't give you what you want.
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Is there an easier way to trim a string?
Already done that. It's all in the
file if you download it.
Shows my code, shows the result I
want, shows everything and all
you have to do is press
a button.
Don't think I can make it any simpler.
If you have a suggestion that will work
you can put your code in the button
script and try it.
Really don't see what your problem is.
Care to tell?
file if you download it.
Shows my code, shows the result I
want, shows everything and all
you have to do is press
a button.
Don't think I can make it any simpler.
If you have a suggestion that will work
you can put your code in the button
script and try it.
Really don't see what your problem is.
Care to tell?
Life is just a bowl of cherries.
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Contact:
Re: Is there an easier way to trim a string?
You need to understand that the engine 'sees' the string as you tell it to, so it can be an item list, or just a string of chars.bjb007 wrote:Done some testing with the ideas offered.
They all suffer from the same fault - OK for
one "Trim" but don't work for repeated
trims.
So I'd use Jan's one liner, but make it a two liner:
Code: Select all
if char -1 of tString is comma then delete char -1 of tString -- it's a string of chars
put empty into item -1 of tString -- it's an item list
Re: Is there an easier way to trim a string?
But no single line of comment what you really want to achieve in the end!bjb007 wrote:...
Shows my code, shows the result I
want, shows everything and all
you have to do is press
a button...
The script shows in as cumbersome way that you want to delete the last number in the field every time you click the button!
Hey, your grumpyness, we are definitively no clairvoyants, although we are working on it

Is there an easier way to trim a string?
Klaus
Found the "character" function which provides
a more all-purpose way to trim a string.
Also solved the comma-delimited "delete item"
problem by having a comma after the last item
in the field although it's not allowed in programmed operations.
Found the "character" function which provides
a more all-purpose way to trim a string.
Also solved the comma-delimited "delete item"
problem by having a comma after the last item
in the field although it's not allowed in programmed operations.
Life is just a bowl of cherries.
Code: Select all
replaceText(t, "[ \t]+$", "")