Replace dot in a number [duplicate] - javascript

This question already has answers here:
Removing everything except numbers in a string
(7 answers)
Closed 3 years ago.
I want to replace the dot in a number in Javascript with regular expression; if country_temp is, for example, 1.234, how can I put the value 1234 in country_temp2?
I have tried the following:
const country_temp2 = country_temp.replace(/[a-zA-Z]*\**\s*\./g, "")
but it's not working.
Edit: the original string is composed by characters, asterisk, a number and a dot
Sorry, but I have written in a very fast way.

Try this:
country_temp.replace(/\./g,'')

Related

SyntaxError: Number.toString() in Javascript [duplicate]

This question already has answers here:
Calling member function of number literal
(3 answers)
Closed 6 years ago.
Why do I get an error on this, in Javascript:
10000000.toString();
You can see an example in here:
http://jsbin.com/kagijayecu/1/edit?js,console
It's because the JS parser is expecting more digits after the "." rather than a method name, e.g. 1000000.0, and in fact 1000000.0.toString() will work as expected.
wrap it inside () like this (10000000).toString()
When JS parse meets dot after digit it expects floating-point literal, e.g. 1000000.0

Replacing “index” array string using Javascript regex [duplicate]

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

extracting text between two characters [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 6 years ago.
Having a string like:
"*this* not that"
I can select *this*
\*(.*?)\*
but I'm not able to get only this.
what I am trying to achieve is to replace -this- by a new string. What's the easiest way to do that ?
you can try:
"*this* not that".replace(/\*.*\*/,'*new_string*');
//"*new_string* not that"

Explode string without separators [duplicate]

This question already has answers here:
How to get character array from a string?
(14 answers)
Closed 7 years ago.
I have a string like 12345 and I need to explode it to [1,2,3,4,5]. Normally, I would use split, but there are no separators in here. I could use substr (getting length, making loops), but I will probably have a lot of those strings, so it may not be good for performance. What can I do?
Simply use an empty string as a delimiter:
"12345".split('');

JavaScript / jQuery: how to split string with multiple values [duplicate]

This question already has answers here:
How do I split a string, breaking at a particular character?
(17 answers)
Closed 8 years ago.
I have a string that always contains 8 variable values that are separated with a hypen (-) like in the following example:
5-2-2-2-2-2-2-1
What is the best way to split this into 8 separate values so that I can use each of them in a variable if the values can be either an integer or the value 'n/a' ?
Many thanks for any help with this, Tim.
var str = '5-2-2-2-2-2-2-1';
var parts = str.split('-');
for (var i=0;i<parts.length;i++){
console.log(parts[i]);
}
You are searching for the String.split() method

Categories

Resources