Andrew Lyle Global Moderator Posted February 5, 2011 Global Moderator Share Posted February 5, 2011 Right now I have a ajax/jquery script that sends a variable to a script and it replies back with the data I want. I want to add a character to the string, in front of a specific character. I want to take a string like this: "tommy51" and replace it with: "tommy 51" I also want to assign the output data to a value of ID "name". Link to comment Share on other sites More sharing options...
0 RoomKid Posted February 6, 2011 Share Posted February 6, 2011 Since you said, in front of a specific character, you could do something like this var mystring = "tommy51"; mystring = mystring.replace('51', ' 51'); alert(mystring); Regex would be your best choice :) but the above will work well. Link to comment Share on other sites More sharing options...
0 nub Posted February 6, 2011 Share Posted February 6, 2011 Why do you want to do this? Why can't it send it back with the space? Link to comment Share on other sites More sharing options...
0 Andrew Lyle Global Moderator Posted February 6, 2011 Author Global Moderator Share Posted February 6, 2011 Cause there is also a period, dash, etc between the characters. That was just an example :) Link to comment Share on other sites More sharing options...
0 jackwanders Posted February 9, 2011 Share Posted February 9, 2011 The solution depends on a few things. Let's say you want to take string A and insert character B before character C - Will B always be the same character? i.e., will you always be inserting the same character into your strings? - How will you determine C? Is C always the same character? What if that character appears more than once in the string? Link to comment Share on other sites More sharing options...
0 Dom Posted February 10, 2011 Share Posted February 10, 2011 Yeah we need more case scenarios, the idea would be to elaborate one regex to rule them all, but without more info, we're just shooting blindly. Link to comment Share on other sites More sharing options...
Question
Andrew Lyle Global Moderator
Right now I have a ajax/jquery script that sends a variable to a script and it replies back with the data I want.
I want to add a character to the string, in front of a specific character.
I want to take a string like this:
"tommy51"
and replace it with:
"tommy 51"
I also want to assign the output data to a value of ID "name".
Link to comment
Share on other sites
5 answers to this question
Recommended Posts