How to Remove two consecutive double quotes from array after split [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a requirement where i will get the input from the user. He can enter
"features1,feature2",feature3,"feature4"
something like this. I'm using this
let arr: any = message.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/)
to split the string and i'm getting result like
[""feature1,feature2"","feature3",""feature4""]
but i want the result like this
["feature1,feature2","feature3","feature4"]

I don't thing what you're trying to achieve is possible only using split function.
After you split, loop over the error and replace " with `` (empty).
const message = `"features1,feature2",feature3,"feature4"`;
let arr = message.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/);
arr = arr.map(el=>el.replace(/"/g,''));
console.log(arr);

Related

Finding difference between two strings and storing the difference one in other string in javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I need to find difference between two strings.
string newemails = peter#xyz.com,john#xyz.com,harry#xyz.com,prince#xyz.com;
string oldemails = peter#xyz.com,john#xyz.com,johnson#xyz.com,harry#xyz.com,prince#xyz.com;
The expected output is johnson#xyz.com and log it to the new string.
Is there any way to do this in JavaScript?
You can split the strings by comma, then filter out the newemails from the oldemails:
var newemails = 'peter#xyz.com,john#xyz.com,harry#xyz.com,prince#xyz.com';
var oldemails = 'peter#xyz.com,john#xyz.com,johnson#xyz.com,harry#xyz.com,prince#xyz.com';
var newemailsArr = newemails.split(',');
var diff = oldemails.split(',').filter(m => !newemailsArr.includes(m)).join(',');
console.log(diff);

Javascript Split string into multi-dimensional array [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm looking to split a string into a javascript multi-dimensional array. Assistance or pointers would he hugely appreciated.
String consists of 3 fields - comma delimiter for each field, and # delimiter for each record
Data/String:
Big Ben,www.myurl.com,2020-10-03#Buckingham Palace,www.myurl2.com,2020-15-03#
thank you in advance.
The following gets what you're after.
let string = 'Big Ben,www.myurl.com,2020-10-03#Buckingham Palace,www.myurl2.com,2020-15-03#';
let result = string.split('#').filter(function(el) {return el.length !== 0}).map(row => {
return row.split(',');
});
console.log(result);

Finding a faster way of checking characters in js [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to make something that gives an output based on your input. I would like it to take every letter and produce something with the next letter in the alphabet. So if I entered "Hello" it would produce "Ifmmp". The only way I can think to do this is with a series of ifs and else ifs, but I would like to know if there is a faster way.
You can use the String.fromCharCode feature. For example:
let myChar = 'c';
let nextChar = String.fromCharCode(myChar.charCodeAt(0)+1);
console.log(nextChar) // 'd'
In your case, you would replace 'c' with your character variable.

Regular express to match `command--o1--o2--o3` [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a string like command--o1--o2--o3 ( command,o1,o2,o3 are arbitrary words)
And I want get [o1, o2, o3] though a Regular Expression(Not a array operation or other ways. JUST only use Regular Expression).
Is there any idea to accomplish this !?
If you're using JavaScript, and assuming you want all strings after a --, you may do
var things = str.split(/--/).slice(1)
If you just want to get the 2 characters words following --, then you may use
var things = str.match(/--\w\w/g).map(function(s){ return s.slice(2) })

Split a given string and get last split value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a string like
count-contribute-1
count-contribute-11
count-contribute-1111
Here I want to split the string and get the last split value (i.e 1 , 11, 1111);
How can I do it?
split() on - and pop() of the last value
string.split('-').pop()
Use .pop() to get the last item from the array created by .split()
"count-contribute-1".split('-').pop();
Also you can get last part of numbers using regular expression. Like this:
s = "count-contribute-111"
s.match(/\d+$/)
//return "111"
It doesn't matter what separator you use.
s = "count-contribute-+*%111"
s.match(/\d+$/)
//return "111"

Categories

Resources