Jump to content

Replace and increment?


lfernando

Recommended Posts

Hi there!

Hoping someone can help me with this very specific issue :)

 

I have a string that looks like this:

var1
var2
X
var3
var4
X
var5

 

I need to find the highest number next to var (in this case 5), and to replace X with the following number (in this case var6).

So after the replace, the string would look like this:

 

var1
var2
var6 (this x has been replaced for var6)
var3
var4
var7 (this x has been replaced for var7)
var5

 

Any ideas!?

 

Thanks!

Link to comment
Share on other sites

Hi there! Thank you so much for your quick reply!

This works great, except its picking up all numbers on the string. I only want to pick up the number after "var", so this string:

 

var3
var5
x
var6
something8
something9

 

should be replaced for

 

var3
var5
var7 (this x has been replaced for 7)
var6
something8
something9

 

 

Link to comment
Share on other sites

Thanks!! That's exactly what I needed.You made my week! :)

 

I'm using "var" in this example but in reality the number is inside of a dropdown list, like this:

"<br><select name=". $var.  $NUMBER . "_tab1 ><option value='blank' selected></option><option style='color:green;' style value=pass>Pass</option><option style='color:red;' value=fail>Fail</option><option style='color;gray;' value=na>N/A</option></select> "

 

Do you know how to incorporate this into your code?

 

Thank you again for all your help

 

 

Link to comment
Share on other sites

Thanks!! That's exactly what I needed.You made my week! :)

 

I'm using "var" in this example but in reality the number is inside of a dropdown list, like this:

"<br><select name=". $var.  $NUMBER . "_tab1 ><option value='blank' selected></option><option style='color:green;' style value=pass>Pass</option><option style='color:red;' value=fail>Fail</option><option style='color;gray;' value=na>N/A</option></select> "

 

Do you know how to incorporate this into your code?

 

Thank you again for all your help

 

I have no idea what you're doing.  If you would explain what you want to accomplish at a higher level than searching and replacing, maybe it will be much easier than you thought.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.