Hi,
I have one text file, which have lot of data. I want to remove the extra spaces and special characters from it.
I have use, Regex.Replace( word1, " {2,}", " ") But there is no change in output.
Please give suggestions.
Thanks.
@ClaytonM @palindrome @dmdixon75
1 Like
J0ska
March 27, 2019, 1:58pm
2
Hi,
It would be worth to give sample of text file
Cheers
Hi,
Please find the screen shot of Text file.
Please use replace function for whichever characters you need to replace.
String1.Trim.Replace(“$”,“”).Replace(“%”,“”).Replace(“#”,“”)
Hi,
But it will not remove the extra spaces.
HI,
I tried with .trim, But no changes in output. Spaces are same.
J0ska
March 27, 2019, 2:14pm
8
Hi @Jayesh_678 ,
Right, it is hard to validate regex vs. screenshot
In principle your statement is correct and works so the problems lies in the text file, I guess.
Cheers
EDIT: I mean that spaces are likely not spaces (ASCII 32)
J0ska
March 27, 2019, 2:16pm
9
Hi @Vivek_Arunagiri ,
Trim method will remove only trailing/leading spaces but not spaces in between string, right?
Cheers
So, we can not remove that?
Actually because of that spaces and special characters I can not split the exact value from all documents.
J0ska
March 27, 2019, 2:35pm
12
You could try Regex.Replace( word1, “\s{2,}”, " ")
And check in HEX editor if spaces are spaces
palindrome
(Nitin Safaya)
March 27, 2019, 2:38pm
13
Did you tried Regex.Replace(text, “\s+”," ")
Hey,
It works.
Is there any syntax, so we can keep A-Z and 0-9 only?
Hey @palindrome ,
It works.
Is there any syntax, so we can keep A-Z and 0-9 only?
you can try this to replace all but letters and digits.
Regex.Replace(text, “[^\w\d]+”, “”)
3 Likes
system
(system)
Closed
March 30, 2019, 3:56pm
17
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.