×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Insert fixed characters into alphanumeric string

Insert fixed characters into alphanumeric string

Insert fixed characters into alphanumeric string

(OP)
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.

RE: Insert fixed characters into alphanumeric string

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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close