Remove whitespaces after second comma

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richh
Posts: 41
Joined: Tue Jan 25, 2011 8:48 pm

Remove whitespaces after second comma

Post by richh » Wed Jan 26, 2011 5:28 pm

Ok... so I have been curious to see how powerful LiveCode is when Text manipulation. I am still getting my barrings straight with documentation and syntax.

lets say I have a string like this

Code: Select all

put "this, is,      a, test" into sString

now, I want to go ahead and remove the white spaces after the second comma

I was looking at the documentations for LTRIM or TRIM but did not see anything. Suggestions on how to do this in LiveCode?

TIA
- Rich

LiveCode 4.6.4
Dell Latitude E6400 running Windows XP SP3 / Mac Pro, Macbook Pro & Mac Mini running OS X 10.6.4

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Remove whitespaces after second comma

Post by Klaus » Wed Jan 26, 2011 5:43 pm

Hi Rich,

ONE way is this:
...
replace SPACE with empty in item 3 of tString
...
Yep, you might need get used to this "natural" approach :D


Best

Klaus

richh
Posts: 41
Joined: Tue Jan 25, 2011 8:48 pm

Re: Remove whitespaces after second comma

Post by richh » Wed Jan 26, 2011 5:49 pm

Klaus,

your becoming my hero :)

thank you again.
- Rich

LiveCode 4.6.4
Dell Latitude E6400 running Windows XP SP3 / Mac Pro, Macbook Pro & Mac Mini running OS X 10.6.4

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Remove whitespaces after second comma

Post by Klaus » Wed Jan 26, 2011 5:57 pm

I feel flattered! :oops:

But not too much, I work with LiveCode (and its ancestors MetaCard/Revolution)
since 1999 and it would be a shame if I could not answer this 8)


Best

Klaus

doc
Posts: 148
Joined: Fri Jun 09, 2006 4:30 pm

Re: Remove whitespaces after second comma

Post by doc » Wed Jan 26, 2011 6:01 pm

Nice one, Klaus! :)

@Rich
A few words of encouragement...
Learning LiveCode from *any* BASIC-like language perspective can be daunting at first ...but hang in there.
(nothing works quite like you think it should)

Nothing comes close to LiveCode when it comes to easy and powerful text processing. Absolutely nothing!
Once you get the hang of it, you won't want to use anything else and syntax like LTRIM or TRIM will become almost foreign to you.

-Doc-

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Remove whitespaces after second comma

Post by Klaus » Wed Jan 26, 2011 6:08 pm

Hi Rich,

I also strongly recommend to check these stacks here:
http://www.runrev.com/developers/lesson ... nferences/


Best

Klaus

wsamples
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 264
Joined: Mon May 18, 2009 4:12 am

Re: Remove whitespaces after second comma

Post by wsamples » Wed Jan 26, 2011 6:29 pm

Yes, the amount of help that Klaus provides the community makes him one of its greatest assets.

I see he has removed my incomplete (and therefore broken and misleading) repeat loop :D, although I was coming back to fix it.

Anyway... Klaus's first example removes all spaces in the third item, which may not be what you want, so if you use

Code: Select all

replace "  " with "" ...
you will get the modification you are looking for (provided there isn't another double space in there that you would like to preserve!).

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Remove whitespaces after second comma

Post by Klaus » Wed Jan 26, 2011 7:11 pm

wsamples wrote:...I see he has removed my incomplete (and therefore broken and misleading) repeat loop :D, although I was coming back to fix it.
Really? Where and when? :shock:

richh
Posts: 41
Joined: Tue Jan 25, 2011 8:48 pm

Re: Remove whitespaces after second comma

Post by richh » Wed Jan 26, 2011 7:32 pm

Thank you all for your responses....

When I was learning to program in RB, it took me a while to understand OOP and how to "think different" compared to liner programming. As doc said, LiveCode will take some getting used to and will continue to read as much documents as I can.

I am very close to making a decision on purchasing LiveCode. I have emailed the development team and waiting response concerning licensing and what I am entitled to. I have been on the hunt for a second language to put in my back pocket and I hope LiveCode is it.

Moving forward, I am hoping to press my luck one more time with removing white spaces....

if I had a line that was "this$ is $ a $ test"

like before, if I wanted to remove the white spaces in item 3, how can I tell LiveCode to use $ as a delimiter?
- Rich

LiveCode 4.6.4
Dell Latitude E6400 running Windows XP SP3 / Mac Pro, Macbook Pro & Mac Mini running OS X 10.6.4

wsamples
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 264
Joined: Mon May 18, 2009 4:12 am

Re: Remove whitespaces after second comma

Post by wsamples » Wed Jan 26, 2011 7:36 pm

It wasn't you??? :lol: I just assumed it was you, wearing the Mod hat... In any event, my feelings weren't hurt; what I had posted was seriously flawed and definitely not going to help anyone! Whoever deleted it couldn't have known I would catch it and come back to try to correct it.

(I had been distracted and I suppose it's possible my carelessness could have been so extreme that I didn't realize I had never successfully posted it :roll: )

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Remove whitespaces after second comma

Post by Klaus » Wed Jan 26, 2011 7:47 pm

Hi Rich,
richh wrote:...how can I tell LiveCode to use $ as a delimiter?
...
set the itemdel to "$"
## itemdel = short for itemdelimiter
...
You can define ANY single character as an itemdelimiter, which is a wonderful thing

@wsamples
No, that surely wasn't me!
I know how to differ Viagra Ads from "real" postings" :D


Best

Klaus

Post Reply