Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert fixed characters into alphanumeric string

Status
Not open for further replies.

niwsbuc

Technical User
Sep 24, 2019
1
US
I have a text string that also includes numbers. Based on where my cursor is within the string, I'm wanting to be able to add <Y> to the beginning of a number and </Y> at the end of a number.

An example text string would be: There are 21 rocks in my collection -- 2 of them are quartz. I want the string to be: There are <Y>21</Y> rocks in my collection -- 2 of them are quartz.

If my cursor is to the left of 21, between the 2 and the 1 or to the right of the 1, I'm looking for a script to put the <Y> in front of the 2 (in 21) and put a </Y> at the end of the 1 as shown in the example. Pretty much, the cursor has to be next to one of the numbers that I want to put <Y> in front of and </Y> behind.

If there is only one number in the text string, I want to do the same thing... put a <Y> in front of the first number and a </Y> behind the last number.

An example text string would be: 2 of my rocks are quartz. I want the string to be: <Y>2</Y> of my rocks are quartz.
As long as my cursor is to the immediate left or right of the 2, I want to put <Y> in front of and </Y> behind the number.

It's just beyond my scope of knowledge.
 
You didn't post any code, but if you had something like
Code:
s = "There are 21 rocks in my collection -- 2 of them are quartz."

...there are ways to find the numbers and insert the <y> and </y>.

But what do you mean about the cursor?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top