This question already has answers here:
JavaScript .replace only replaces first Match [duplicate]
(7 answers)
Closed 6 years ago.
I would like to have the result :
28,12,2016
From this string "28/12/2016"
I tried :
("28/12/2016").replace('/',',');
==>"28,12/2016"
I don't know how to delete the second /and the " "
use split and join method
var a="28/12/2016";
var ans=a.split("/").join(",");
console.log(ans);
Related
This question already has answers here:
Last segment of URL with JavaScript
(30 answers)
Closed 1 year ago.
I have a string which is
file:///storage/emulated/0/Android/data/com.myapp/files/Pictures/00cb3b0b-45d5-486b-8f33-0fa3bf2285ff.jpg
And I want to extract the string after the last / which will be 00cb3b0b-45d5-486b-8f33-0fa3bf2285ff.jpg
How can I extract the last part of this string and store it in a variable ?
I extracted the last part of string like this :
mystring.substring(mystring.lastIndexOf('/') + 1)
This question already has answers here:
Regex using javascript to return just numbers
(14 answers)
Closed 6 years ago.
with the following code can get the 1 in the string.
var match = /[0-9]+/.exec('[1][2]');
console.log(match);
How do i get the 2 and not the 1 ?
Try with this regex
console.log(/(\[[0-9]\])+/.exec('[1][2]'));
I think it's only a matter of escaping the square brackets
This question already has answers here:
How to get the last character of a string?
(15 answers)
Closed 8 years ago.
I have a string I am trying to get the last character with jquery. How would I do that?
var stringTemp = "fieldNameWithIndex_1";
stringTemp.charAt(stringTemp.length-1);
or
stringTemp.slice(-1);
Use .split():
stringTemp.split('_')[1]
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Replace all spaces in a string with '+'
how to remove ,#contacts.Assessor.firstname# #contacts.Assessor.lastname# and
,#contacts.Assessor - Secondary.firstname# #contacts.Assessor - Secondary.lastname# from a
string in javascript?
Thanks
Simply use .replace()
string = string
.replace(',#contacts.Assessor - Secondary.firstname# #contacts.Assessor - Secondary.lastname#', '')
.replace(',#contacts.Assessor.firstname# #contacts.Assessor.lastname#', '');
Also take a loot at this related question
This question already has answers here:
Split large string in n-size chunks in JavaScript
(23 answers)
Closed 9 years ago.
I want to split string
"abcdefgh"
to
"ab","cd","ef","gh"
using javascript split()
"abcdefgh".split(???)
Can you please help ?
Instead of split, try match:
var text = "abcdefgh";
print(text.match(/../g));
prints:
ab,cd,ef,gh
as you can see on Ideone.