Click here to Skip to main content
16,004,458 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Function RemoveJunk(ByVal Readlinevalue As String) As String

Readlinevalue = Readlinevalue.Replace(vbLf, String.Empty)

Regex.Replace(Readlinevalue, "[^A-Za-z0-9\-/]", String.Empty)

Return Readlinevalue

    End Function


What I have tried:

well i tried my best but junk exist and invisible can you improve this code
some thing like ascii or can do better job ?
Posted
Updated 8-Jul-16 4:40am

1 solution

Um. You do realise that Regex.Replace doesn't change the original input, but returns a value instead?
Regex.Replace Method (String, String, String) (System.Text.RegularExpressions)[^]
So try:
C#
Public Function RemoveJunk(ByVal Readlinevalue As String) As String
    Readlinevalue = Regex.Replace(Readlinevalue, "[^A-Za-z0-9\-/]", String.Empty)
    Return Readlinevalue
End Function
 
Share this answer
 
Comments
Member 10974007 9-Jul-16 0:23am    
see i don't note that for a long time i was using that code .
can any more improvement made to same
OriginalGriff 9-Jul-16 2:18am    
You mean performance wise?
Probably - Regex isn't particularly efficient, but you'd probably need to do some performance tests to check the efficiency of the various possibilities.
There is a tip I wrote on a similar subject a few years ago:
http://www.codeproject.com/Tips/312312/Counting-Lines-in-a-String
Which does performance calculations for the various ways of checking newlines - which is a similar problem in many ways - and it gave some surprising results.
It's in C#, not VB, but it's pretty easy to understand (and has an "executive summary" which doesn't need code familiarity) and may be worth a read. (and you can translate between the two languages with
http://converter.telerik.com/
anyway).
Ultimately, you'll need to write a few different pieces of code and use Stopwatch to compare them to know for sure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900