I am trying to remove a leading quote mark from the start of a string. I have tried using substring but it is not working. I am not sure what I am doing wrong. Or if there is a better way of doing it.
String name = " "Score is positive "
name.substring(1).
I am trying to remove the starting quote mark " to get the following output:
Your example string is surrounded by quotes. The quick way is to do this:
name.Replace("""", String.Empty).Trim, which will remove whitespace surrounding the string as well. Remove the Trim part if you want to keep the whitespace.
The “safe” way to do this (i.e. without risking removing something other than quotation marks) is:
name = System.Text.RegularExpressions.Regex.Match(name.Trim, "^""", String.Empty). This will only remove the first character if it is the quotation marks character ". Again, if you want to keep the whitespace, remove the Trim portion, but be warned that if your string starts with a space, this will only remove the " if you leave the Trim portion on.
I prefer option 2. It looks safer. I tried to implement in UiPath but it is giving me errors with the word Matching. Do you need to install libraries to use RegEX in UiPath.
Hi Karthick, yes I get them in all my string and at the start. What does the c represent? I just do not want to remove actuall quote mark used in the string though like for sarcasm. Just the leading ones that seem to come through.
name.Replace("""", String.Empty).Trim will work for removing all quotes. If it isn’t working, there is something else wrong in the workflow. If this solution does not work, please share your workflow with proprietary data replaced with dummy data.
@Anthony_Humphries Hi buddy. That works fine. But I do not want to remove all the quotes. I want to keep the one in the middle of the sentence, if it contains any. I just want to remove all leading one. It is the regex one that is not working.
That’s a carriage return. In Windows systems, anytime the Enter key is pressed to start a new line, a carriage return \r and newline \n is added to the end of the string. In Unix and Linux systems, only a \n is added to the end. These characters are invisible when reading text data, but a machine sees these characters and presents them in a way you can perform operations on them as though they were any other character on the keyboard.