Replace question
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Replace question
I need to replace only the last occurrence of - in a string but am not having any luck.
Example;
put 1-2-3 into tTemp
replace character 4 with " " in tTemp
That doesn't work
replace the last "-" with " " in tTemp
Doesn't work either.
I don't know what else to try. Thank you in advance.
Example;
put 1-2-3 into tTemp
replace character 4 with " " in tTemp
That doesn't work
replace the last "-" with " " in tTemp
Doesn't work either.
I don't know what else to try. Thank you in advance.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: Replace question
Replace will only replace all of the occurrences.
Try something like this:
Try something like this:
Code: Select all
put space into char 4 of tTemp[
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: Replace question
Perfect solution, thank you.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Replace question
Hi.
Is your data always such that the fourth char is the one that needs replacing?
If not, you could set up a repeat loop:
Now the last "-" is replaced, wherever it lies.
Craig Newman
Is your data always such that the fourth char is the one that needs replacing?
If not, you could set up a repeat loop:
Code: Select all
on mouseUp
repeat with y = the number of chars of yourText down to 1
if char y of yourText = "-" then
put space into char y of yourText
exit repeat
end if
end repeat
end mouseUp
Craig Newman
Re: Replace question
Thnx Craig,
You are correct that its not always the 4th character. Here is my code, but I like yours better.
You are correct that its not always the 4th character. Here is my code, but I like yours better.
Code: Select all
put the length of sandl into tLength
put "1" into tTimes
repeat until tTimes > tLength
if character tTimes in sandl = "-" then
put tTimes into lastHyphen
end if
put tTimes + 1 into tTimes
end repeat
put " " into char lastHyphen of sandl
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Replace question
So do I.
My handler only addresses a single line, right? It exits when it finds the lastMost hyphen.
Don't tell Jacque, but can you post a modified handler that loses the lastMost hyphen in each line, and skips those that do not need processing?
Craig
My handler only addresses a single line, right? It exits when it finds the lastMost hyphen.
Don't tell Jacque, but can you post a modified handler that loses the lastMost hyphen in each line, and skips those that do not need processing?
Craig
Re: Replace question
<Going to go look for Jacque, she definitely needs to look at what your *cough*{homework}*cough* doing>
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Replace question
Yet another option.
Code: Select all
set the itemdelimiter to "-"
put (item 1 to -2 of sandl) & space & (item -1 of sandl) into sandl
shiftLock happens