Goutham R
Goutham R

Reputation: 47

String value coming with two double quoted to .ts

If I given the normal value say hello in input field, it is coming like "hello", And if I have given the value like "hello", it is storing like ""hello"" . How to identify this two double quoted string and make it to one double quote .?

Upvotes: 0

Views: 1265

Answers (2)

Ranjeeth Rao
Ranjeeth Rao

Reputation: 155

Without code, it is impossible to predict why the input field is adding double quotes to the value.

However, if you are using typescript or javascript, you can use the following to rectify the 2-double quotes issue:

let str = '""hello""';
if(str.startsWith("\"\"") && str.endsWith("\"\"")){
    str = str.substr(1,str.length-2);
  // str = str.replace(/\"\"/g, "\""); //Alternatively you can use this, if there will not be 2-double quotes in between your string
}
store(str);

Upvotes: 1

Maddy Blacklisted
Maddy Blacklisted

Reputation: 1190

Use str.replace(/"/g, '') and wrap your string with artificial quotes. Something like

function stripQuotes(str) {
    let stripped = str.replace(/"/g, '');
    return '"'+stripped+'"';
}

Now calling stripQuotes(""Hello"") will return "Hello", your desired result.

Upvotes: 2

Related Questions