Is it possible to bine these two lines of code into one?
Meaning, can we do a ToString() and .replace() in one line?
var mySecondVar = myFirstVar.ToString()
mySecondVar = mySecondVar.replace("a","u");
Is it possible to bine these two lines of code into one?
Meaning, can we do a ToString() and .replace() in one line?
var mySecondVar = myFirstVar.ToString()
mySecondVar = mySecondVar.replace("a","u");
Share
Improve this question
asked Jan 25, 2016 at 3:17
ConfusedDeerConfusedDeer
3,4158 gold badges46 silver badges77 bronze badges
2
- 1 Have you actually tried? – PM 77-1 Commented Jan 25, 2016 at 3:21
-
What is
myFirstVar
value? – Tushar Commented Jan 25, 2016 at 3:25
2 Answers
Reset to default 5Yes, you can chain the methods.
myFirstVar.toString().replace('a', 'u')
Note:
ToString
should betoString
String#replace
will only replace the first occurrence of the string. To replace all occurrences use replace with RegEx
You can use:
var mySecondVar = myFirstVar.toString().replace("a","u");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744272374a4566163.html
评论列表(0条)