Removing Spaces from String

@“Change in address of the Official Point of Acceptance of Transactions (OPAT) of
Computer Age Management Services Limited (CAMS) Located at Himmatnagar, Gujrat.”

so above is my String, I read it as a string, but as you can see there is “@” which .ToString is unable to read, and I think this whole text is not considering to be a string . So I want to replace this @ with “” and " with “”

Hi,

@ sign is special character of C# syntax. it means verbatim text and this sign is not part of content.
Please check the following document in details.

Regards,

1 Like

@susHI_Bae,

It’s just C# syntax thing. Any error or issue you are facing because of this?

Thanks,
Ashok :slight_smile:

Yes, I got an error saying, Illegal Characters in path

@susHI_Bae,

Please share the error description and screenshot.

Thanks,
Ashok :slight_smile:

1 Like

I am Fetching some data from a DT and All the other Text file name is okay, but this number 17 is bugging me, and it says Illegal Characters in path

Hi,

Can you try the following expression? These expressions remove invalid caharacters for file or path.

 yourString = System.Text.RegularExpressions.Regex.Replace(yourString,"["+System.Text.RegularExpressions.Regex.Escape(String.Join("",System.IO.Path.GetInvalidPathChars))+"]","")

OR

yourString =System.Text.RegularExpressions.Regex.Replace(yourString,"["+System.Text.RegularExpressions.Regex.Escape(String.Join("",System.IO.Path.GetInvalidFileNameChars))+"]","") 

Regards,

1 Like

@susHI_Bae,

Root cause of the error is, your PdfName variable value have special character which is dividing the single string in two lines. This string File Explorer not accepting as a valid name.

If you copy it to notepad or excel you will see it. It’s getting splited in two lines without word wrap on.

Get it converted to single line using below code provided by Yoichi.

System.Text.RegularExpressions.Regex.Replace(PdfName,"["+System.Text.RegularExpressions.Regex.Escape(String.Join("",System.IO.Path.GetInvalidFileNameChars))+"]","")

Thanks
Ashok :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.