How to manage strings that contain quotes?

Hi

I am trying to use a block of text I copied from somewhere as a string in studio. The problem is that the text contains quotes, which I cannot edit or remove. I know that if you want quotes within a string to treated as part of the string, you have to use double quotes.

For example, if I want my output string to be mystring “123”, I can write it in studio as "mystring ““123"””.

But since I cannot edit the text and add the extra quotes inside the string, is there any way to make studio understand that I want the whole text block (including any quotes inside it) to be treated as one string?

I tried different things, like "“mystring “123"”” but haven’t found a solution yet.

@Ioana_D
Welcome to the forum

Not fully clear on the requirement. Maybe you are looking for the following:

grafik

Hi Peter

Thanks for the reply.

The options you shared would normally be very helpful, but I was wondering if there is a way to only work with the ends of the string, assuming I can’t edit the quotes around 123. The text i need to use as string is copied from somewhere, and it contains quotations in several places, so I would like to avoid having to make changes in it.

For example, if I wanted to do this in python, to get the output as mystring “123”, my input would be 'mystring “123” ', thereby only manipulating the ends of the string.

I hope it makes sense.

unfortunately not all is clear. But we do feel you are close to have it done

not clear, but if cleansing is needed we would recommend to do it

please use the </> format button or screenshots. we do need to see all details including surrounding chars

Also have a look here:
grafik

we do trim the surrounding ’

If the double quotes are in the value in the string variable, they have no effect on anything. You can just use the variable like you would any other. Are you having a specific problem that you’re trying to solve?

Hi @Ioana_D

you can use Chr(34)+your_string+Chr(34) to wrap the text with double quotes. This way you need not manipulate the actual string
and for single quotes you can use Chr(39).
hope this is helpful

image

Hi Paul. Yes, the double quotes are in the value of the string (around Reg. 1). They do, however, seam to have an effect as I get an error saying Compiler error(s) encountered processing expression ““183.91 ml Set mark “Reg. 1” (Issued) (Processing) (Completed)””.
End of expression expected.

If I remove the quotes around Reg. 1, then there is no issue. This string is just a sample of a longer text to be assigned to the variable, and the text contains quotes in several places. That’s why I want to find a way to avoid manipulating inside the string.

I actually did a not very elegant workaround, where I use a dialog box to ask for user input, then save it as a variable. The user input seams to always be regarded as a whole string regardless of the quotes it contains. I would have just like to avoid user input.

Hi Aditya

You mean like this?
(my sting is 183.91 ml Set mark “Reg. 1” (Issued) (Processing) (Completed))

image

Then I get the following error:
Compiler error(s) encountered processing expression “Chr(34)+183.91 ml Set mark “Reg. 1” (Issued) (Processing) (Completed)+Chr(34)”.
End of expression expected.

I tried to put extra quotes around the string and other manipulations but I can’t seam to fix it.

grafik

Hi @Ioana_D

the error is because you need to escape the double quotes for Reg. 1 so if you use below it shoud not give any error.

Chr(34)+"183.91 ml Set mark "“Reg. 1”" (Issued) (Processing) (Completed)"+Chr(34)

alternatively you can store your string in a variable as below
in the below screenshot, your string is held in

str1 variable and it is surrounded with Chr(34).

your string should be still with in double quotes

hope this is helpful