Doubling a character inside a field !

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
fredericbrandt
Posts: 2
Joined: Sun Dec 28, 2014 5:49 pm
Contact:

Doubling a character inside a field !

Post by fredericbrandt » Sun Dec 28, 2014 5:54 pm

Hi !

I'm completely new to Livecode, and I've been experimenting with it since 1 week, I have to do something with my program, but I don't know how to ! I've searched and I've found nothing. So, I have a field and I would like to have something that do the following : If there's a backslash in a string in that field, let's double it up. So an address like FOLDER\FILE\FILE becomes FOLDER\\FILE\\FILE. Do anyone have an idea on how to do that ?

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

Re: Doubling a character inside a field !

Post by Klaus » Sun Dec 28, 2014 6:13 pm

Hi Frederic,

1. welcome to the forum! :D

2. So you want to replace / with // in your field, right?
Since we are talking about Livecode, you can simply:
...
repace "\" with "\\" in fld "xyz"
...
:D

3. You might be interested in these great learning resources:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Doubling a character inside a field !

Post by SparkOut » Sun Dec 28, 2014 8:05 pm

And just in case you already have \\ in the field somewhere, you don't want to end up with \\\\:

put field "xyz" into tData
replace "\\" with "not_to_be_duplicated" in tData
replace "\" with "\\" in tData
replace "not_to_be_duplicated" with "\\" in tData
put tData into field "xyz"

:)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: Doubling a character inside a field !

Post by dunbarx » Sun Dec 28, 2014 10:22 pm

Hi.

Isn't LC great?

But it made me think that there should be a way to create a general function, which changes any string of "/" of any length into "//". So even if you had:

"xx/xx//xx///////xx" you would get "xx//xx//xx//xx". You don't have to worry about the number of "/" strings or their length.

Code: Select all

on mouseUp
put replaceText(fld 1,"/*/","//") into fld 1
end mouseUp
Craig

fredericbrandt
Posts: 2
Joined: Sun Dec 28, 2014 5:49 pm
Contact:

Re: Doubling a character inside a field !

Post by fredericbrandt » Mon Dec 29, 2014 10:39 pm

Thank you for all your answers !
I'm really enjoying livecode because it's much simplier for me than trying to do C++ and other things. It gave me a headache in like 1 hour. I've got to make a Client for a Server which communicate via Telnet (so sockets), and I found that Livecode was the solution ! So thank you guys !

Post Reply