I have a following code,
var x = "X : 0.0001 Y : Globalize.format(50.635676576567, n2) %"
x is a string.
I need to show the x value as ,(need to convert as globalize format)
"X : 0.0001 Y : 50.63 %"
how to achieve this ?
I have a following code,
var x = "X : 0.0001 Y : Globalize.format(50.635676576567, n2) %"
x is a string.
I need to show the x value as ,(need to convert as globalize format)
"X : 0.0001 Y : 50.63 %"
how to achieve this ?
You can achieve this, parse the string and eval() method, refer below code snippet.
var x = "X : 0.0001 Y : Globalize.format(50.635676576567, 'n2') %"
var substring = x.substring(x.indexOf('Y') + 4, x.length - 2);
// assign the value after replacing the string
x = x.replace(substring, eval(substring));
console.log(x);
But this you need to assign n2 in single quotes or else you can add single quotes by code, for this refer this link
If you need x only as string and not object you can do the following:
var formated = Globalize.format(50.635676576567, n2);
var x = "X : 0.0001 Y :" + formated + "%"
Thanks dudes,
Answer for this query,
var str = "X : 0.0001 Y : Globalize.format(50.635676576567, 'n2') %",
substr;
while (str.indexOf('Globalize.format(') >= 0) {
substr = str.substring(str.indexOf('Globalize.format('), str.indexOf(")") + 1);
str = str.replace(substr, eval(substr));
}