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
}
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
}
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");
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)
In JavaScript:
var index = str.lastIndexOf("_");
var result = str.substring(0, index) + "_id";
jsFiddle: http://jsfiddle.net/fNZkG/