Example this is the string:
"Hello, this is challenging\n" + "you think it is easy?\n" + variableName + " 3 + 4 = 7\n"
Dim example = """Hello, this is challenging\n"" + ""you think it is easy?\n"" + variableName + "" 3 + 4 = 7\n"""
I want to use programming approach to arrange the string becomes:
"Hello, this is challenging" + newline + "you think it is easy?" + newline + variableName + " 3 + 4 = 7" + newline
Dim output = """Hello, this is challenging"" + newline + ""you think it is easy?"" + newline + variableName + "" 3 + 4 = 7"" + newline"
So as you can see, it involves in getting the text inside quotation
So I am thinking:
1. use regex to get the quotation, but as you can see we will left out the variableName
2. I am thinking to split using + sign, but as you can see, there will be false positive in " 3 + 4 = 7"
tell me what do you think, is it easy? Is there another steps?
Updated example and output:
Dim example2 = """Hello, this \nis challenging\n"" + ""you think it is easy?\n"" + variableName + "" 3 + 4 = 7\n"""
Dim output2 = """Hello, this "" + newline + ""is challenging"" + newline + ""you think it is easy?"" + newline + variableName + "" 3 + 4 = 7"" + newline"
This one-liner works for me:
I get the same as your output.
Here's the updated example working fine:
I get
"Hello, this " + newline + "is challenging" + newline + "you think it is easy?" + newline + variableName + " 3 + 4 = 7" + newline
as per youroutput2
.Here's what's going on in
result2
:All of the double quotes are split out.
On each odd element we replace
\n
with" + newline + "
.Then join back up theparts with
"
.But we had extra sets of double quotes in the form of
newline + ""
, so we just replace these withnewline
.