Inline Trimming in VBScript
This post continues from:
http://sanzon.wordpress.com/2008/05/04/trimming-white-spaces-and-linebreaks-from-strings/
In the last post I went over how to remove linebreaks from the begining and end of a multiline string and at the same time forcing paragraph style post with double linebreaks.
Now in this post I’m going to take it another step with inlinetrimming. What this means is if you have a post like:
“Hi mom,
Today there was a …..”
The problem is that big dent at the begining and end of the paragraph. Now in HTML this normally will turn out to a single line space, unless you preserve spacing by converting chrW(32) into
To remove this excess we simple use a simular method for our inline trimming method.
Public Function InlineTrim(ByVal mySrc As String) As String
If mySrc = “” Then
return nothing
exit function
End If
Dim myStr As String = mySrc
Dim myChar As String = chrW(10) & chrW(32)
myStr = Replace(myStr,chrW(13),”")
do while Regex.IsMatch(myStr,”\n “)
myStr = Replace(myStr,myChar,chrW(10))
loop
do while Regex.IsMatch(myStr,” \n”)
myStr = Replace(myStr,StrReverse(myChar),chrW(10))
loop
return myStr
End Function
This function is very simple. First you go ahead and remove all returns in the string and than search for instances of “\n ” and ” \n” and return it as “\n” and continue to repeat this until all spaces are remove. The ending result is a nice clean block text format with not indents at the begining or end.
Anyway be expecting alot of these post coming up as I redo my class library on my site… the horror of string formating X_x;
well happy coding!