97
Views
7
Comments
Solved
Replacing backslash - single quote " \" " with empty single quotes" " "

Hi All,

I have a scenario where I need to replace replace " \" " to " " ". I am trying to use the replace function but how to do it here.

I could have just use replace (string,"\", "") but is there are data where I will be getting "\" in that data which I don't want to replace.

I am open to any other approach if possible. 


Thanks and Regards

Pranav 

mvp_badge
MVP
Rank: #2
Solution

In addition, in OutSystems, if you want a single (that is, one) double quote inside a Text, you acually type two. So to replace \" by ", you use

Replace(MyText, "\""", """")


mvp_badge
MVP
Rank: #65

Hi Pandey Ji,

You said that you want to replace "\" "  to " " " and than you said there is some data you dont want to replace it . Could you please elaborate your use case a little more so that i can look for solution.

Any example will be great !

Regards,

-PJ-

Rank: #413

Hi Pramod,

Please see the sample data below

"{""load"":""{\""row1\"":{\""col1\"":\""99978444P\"",\""col2\"":\""99978444P\"",\""col3\"":\""99978444P\"",\""pascodeid\"":\""n\VOL3PL-TK2nh\ZXjXN5QV*6RM""}"

We have a column named passcodeid . It consist of value that can have special characters like \ .- ,* in it.

I don't want to remove it.


Thanks

So you trying to get valid JSON or is there some other use case?

To get valid JSON from you example use the following;

Use the following replace rules;

  1. \"" to "
  2. "" to "
  3. "{ to {
  4. }" to }

You example is missing 2 } at the very end of the json. If you follow these rules in this order and then add the 2} you should get valid json. It's is possible that your parser will nag about the invalid escapes in the pascodeid field though, that's not really up to spec.

Good luck,

Vincent

mvp_badge
MVP
Rank: #2
Solution

In addition, in OutSystems, if you want a single (that is, one) double quote inside a Text, you acually type two. So to replace \" by ", you use

Replace(MyText, "\""", """")


mvp_badge
MVP
Rank: #2

You're welcome :). It's one of those things you just need to know :). Happy coding!