How do I replace only the second word?

Just started using Construct 2? Post your questions here

Post » Wed Dec 07, 2016 4:21 pm

Hi in a text with 2 identical words, how I can replace only the second word?
Image
B
4
Posts: 2
Reputation: 208

Post » Wed Dec 07, 2016 6:40 pm

There may be a way to do it with regex.

Another way would be to use the find() expression to find the first occurrence. Then use the mid() expression to get the text after that occurrence. Next use find() on that again to get the location of the second. Then you could rebuild the text around it.
Basically this. It's untested so there may be a few off by one issues.

Var text="Hi, Bill. My name is Bill."
Var temp=""
Var index=0

Index=find(text, "Bill")
Temp=mid(text, index+len("Bill"), len(text)-index-len("Bill"))
Index=find(temp, "Bill")+index+len("Bill")
Text= left(text, index) & "bob" & mid(text, index+len("Bill"), len(text)-index-len("Bill"))
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Thu Dec 08, 2016 1:08 am

Thanks works fine
B
4
Posts: 2
Reputation: 208

Post » Tue Apr 04, 2017 9:12 am

how to replace in a text, this ' by "
B
37
S
15
G
7
Posts: 1,680
Reputation: 9,612


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests