-3

I want to replace string from "_tr9-9" character from a string and replace them with _id character

Here str is changes only _tr9-0 will be changes dynamically remining will be same

str=Test_User_tr9-0;

Ex:

function (str)
{
   var obj=str 
}
cuongle
  • 74,024
  • 28
  • 151
  • 206
kumar
  • 1,117
  • 13
  • 34
  • 58

3 Answers3

1

You can use replace

In javascript

var str = "Test_user_tr9-9 to Test_user_id";
str = str.replace('tr9-9','id');

In C#

var str = "Test_user_tr9-9";
var str = str.Replace("_tr9-9", "_id");
Adil
  • 146,340
  • 25
  • 209
  • 204
1

In C#

string str = "Test_user_tr9-9";
string str2 = str.Replace("_tr9-9", "_id");

In Javascript

var str = "Test_user_tr9-9";
var str2 = str.replace("_tr9-9", "_id");

Note that both in Javascript and C# strings are immutable objects, so the replace/Replace methods return a new modified string (technically in C# the Replace returns the original string if it doesn't find anything to replace)

xanatos
  • 109,618
  • 12
  • 197
  • 280
1

In JavaScript:

var index = str.lastIndexOf("_");
var result = str.substring(0, index) + "_id";

jsFiddle: http://jsfiddle.net/fNZkG/

cuongle
  • 74,024
  • 28
  • 151
  • 206