Search and replace
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Search and replace
Hiya all,
I'm convinced (I might be very wrong though) that I've seen an example somewhere of a multiple search and replace thing. There was a text box with some content and another with some words like this:
white, black
red, green
And it would go through and replace all instances with the first words with the second.
Anyone seen this? I've been through loads of examples and I'm probably missing it somewhere.
Andy.
I'm convinced (I might be very wrong though) that I've seen an example somewhere of a multiple search and replace thing. There was a text box with some content and another with some words like this:
white, black
red, green
And it would go through and replace all instances with the first words with the second.
Anyone seen this? I've been through loads of examples and I'm probably missing it somewhere.
Andy.
Hi Andy,
I'm not sure what you're after. Perhaps this:
put replaceText(fld 1,"red","green") into fld 1
Best,
Mark
I'm not sure what you're after. Perhaps this:
put replaceText(fld 1,"red","green") into fld 1
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
Hi Mark,
That's the gist of it, however the demo I saw allowed for multiple seach and replace, but while thinking about it, I think it's pretty easy anyway.
Correct me if I'm wrong, but I just do a 'for each tLine in fld 'Replacements' and then split on the comma, and replace the first word with the second word.
The whole idea is that I've got a big field of text with lots of abbreviations in it and I want to replace all the abbreviations. I've got another field with the abbreviation and the full word, comma seperated, each one on a seperate line.
You know what, it's difficult to explain, I should go and try it out!
That's the gist of it, however the demo I saw allowed for multiple seach and replace, but while thinking about it, I think it's pretty easy anyway.
Correct me if I'm wrong, but I just do a 'for each tLine in fld 'Replacements' and then split on the comma, and replace the first word with the second word.
The whole idea is that I've got a big field of text with lots of abbreviations in it and I want to replace all the abbreviations. I've got another field with the abbreviation and the full word, comma seperated, each one on a seperate line.
You know what, it's difficult to explain, I should go and try it out!
Andy,
I don't understand you! The replace function replaces all instances of a string. What else do you want?!
Mark
I don't understand you! The replace function replaces all instances of a string. What else do you want?!
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
Told you it was confusing!
Let's say I've got the following paragraph:
Outpt, Output
prev, previous
Off., Office
Stats, Statistics
So I have one text box with the paragraph in that contains a lot of abberviated words and I have another text box with the comma seperated list as above. I then press a button and it goes through all of them and replaces each occurance.
Does that make sense?
Let's say I've got the following paragraph:
Now, in this, plus other documents the same abbreviations are used in the same way, so I want to turn the abbreviations into the full words. I have a list of the abbreviations and full words as a comma seperated file:"Outpt rose by 0.3% from the prev mnth the Off. for National Stats said. Analysts had been expecting outpt to fall by 0.1%
Mnf rose 0.2%, which was also an unexpected rise."
Outpt, Output
prev, previous
Off., Office
Stats, Statistics
So I have one text box with the paragraph in that contains a lot of abberviated words and I have another text box with the comma seperated list as above. I then press a button and it goes through all of them and replaces each occurance.
Does that make sense?
Hi Andy,
What you want is this:
I believe this is almost the same as what you describe in your previous message.
Best,
Mark
What you want is this:
Code: Select all
put fld "Abbrevs" into myAbbrevs
replace comma & space with comma in myAbbrevs
lock screen
repeat for each line myAbbr in myAbbrevs
replace item 1 of myAbbr with item 2 of myAbbr in fld "Paragraph"
end repeat
unlock screen
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
I was just about to post this:
Yours looks much more elegant!
I'll go try it...
Code: Select all
on mouseUp
set the columndelimiter to comma
repeat for each line tLine in fld "fldSearch"
put word one of tLine into tFind
replace "," with "" in tFind
put word two of tLine into tReplace
replace tFind with tReplace in fld "fldText"
end repeat
answer "All done! " with "OK"
end mouseUp
I'll go try it...