Title='U.S. History-part 1'
Dim cleanString As String = Regex.Replace(title, "[^a-zA-Z 0-9-/-]", "")
The result I am getting is : US History-part 1 but I need like : US History part 1 . So if there is hiffen that should also replace with blank space.
The title data is dynamic . I have just given a example.
Below is some example of what it should be from left to right.
U.S. History-part 1 => US History part 1
U.S. History.part.1 => US History part 1
U.S- History : part 1 => US History part 1
Loading
Naveen KumarPosted Oct 16, 2024, 4:25 AM
To remove special characters from string, you can modify the regular expression to remove not just special characters, but also replace hyphens and other unwanted characters like periods, colons, etc. with a blank space.
Check the below code:
Gowtham CpPosted Oct 15, 2024, 5:16 PM
Hello Pinku ,
To clean up a string in Visual Basic .NET and remove special characters while replacing hyphens and periods with spaces, you can use the following code:
In this code, the first
Regex.Replaceremoves unwanted special characters. The secondRegex.Replacereplaces hyphens and periods with spaces. The thirdRegex.Replaceconsolidates any multiple spaces into a single space, andTrim()ensures there are no leading or trailing spaces. This method effectively cleans up the string to meet your requirements.Thanks!