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
-
Da_Elf
- Posts: 311
- Joined: Sun Apr 27, 2014 2:45 am
Post
by Da_Elf » Thu Jul 28, 2016 6:59 pm
I dont get this. Replace isnt replacing chunks properly
Here i have setup a list with
Mike Watkins
Mike
Mark
I want to replace just Mike on line 2.
theList is as above.
theNewName is "Mel"
theOldText is "Mike"
ALL instances of mike get changed
Code: Select all
set the wholeMatches to true
put the lineoffset(theOldText,theList) into changeLine
replace line changeLine of theList with theNewName in theList
-
mwieder
- VIP Livecode Opensource Backer

- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
-
Contact:
Post
by mwieder » Thu Jul 28, 2016 8:25 pm
try
Code: Select all
replace theOldText with theNewName in line changeLine of theList
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Thu Jul 28, 2016 8:32 pm
Code: Select all
--Mark's method above WORKS - for an individual line.
--I'm not absolutely sure how you want the final list to be rewritten but this should help track down what you need to do,
--if you need to replace multiple lines which may or may not be the case.
put "Mike Watkins" & cr & "Mike" & cr & "Mike Baker" & cr & "Mike" & cr & "Mike Peabody" & cr & "Mark" into theList
put "Mel" into theNewName
put "Mike" into theOldText
set the wholeMatches to true
--no "THE" with a function, it's not a property
put lineoffset(theOldText,theList) into changeLine
put line changeLine of theList into tChangeMe
--the bit here:
--[line changeLine of theList]
--resolves to "Mike" in this case, so
--your line:
--replace line changeLine of theList with theNewName in theList
--is equivalent to saying:
--replace "Mike" with "Mel" in theList
--so try:
replace cr & line changeLine of theList & cr with cr & theNewName & cr in theList
--as a quick and simple way to restrict the change to the whole line without resorting to regex
-
Da_Elf
- Posts: 311
- Joined: Sun Apr 27, 2014 2:45 am
Post
by Da_Elf » Thu Jul 28, 2016 8:46 pm
There is only supposed to be one line changed so mark's works perfectly
-
mwieder
- VIP Livecode Opensource Backer

- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
-
Contact:
Post
by mwieder » Thu Jul 28, 2016 9:45 pm
Da_Elf-
I was responding to a *very specific* use case here. SparkOut is right in that you shouldn't have "the" before the function call... I noticed that and forgot to comment on it.
For a more general use, you've already found how to replace *all* occurrences. You'd need a loop if you want to replace more than one and less than all.
-
hpsh
- Posts: 52
- Joined: Tue Aug 25, 2015 8:06 pm
Post
by hpsh » Fri Jul 29, 2016 10:10 am
maybe i don't really get the problem, i am not any good in english, but what about:
Code: Select all
put "Mel" into line 2 in field "list"