Fordraiders
asked on
get rid of ANY spaces SPECIAL CHARACTERS etc in variable
Is there a way in the code below to make sure to no:
padded spaces...extra spaces..special characters do not get added as the variable is being passed along
in the function below ?
Thanks
fordraiders
padded spaces...extra spaces..special characters do not get added as the variable is being passed along
in the function below ?
Thanks
fordraiders
Private Sub PosCompartAdvance()
If Me.CheckBox7.Checked = True Then ' Position
' Me.FldPositionTextBox.Text = mlngData7
If Me.CheckBox9.Checked = True Then
Me.FldPositionTextBox.Text = mlngData7 ' Position
Dim arg As Char = Trim(FldPositionTextBox.Text)
If Char.IsLetter(arg) Then
Dim value As Integer = AscW(arg)
Select Case value
Case 65 To 89, 97 To 121
FldPositionTextBox.Text = Trim(ChrW(value + 1).ToString)
End Select
End If
If Char.IsNumber(arg) Then
Dim value As Integer
' Dim value As Integer = CInt(FldPositionTextBox.Text).ToString ' added to string here 01/25/2011
'Dim value As Integer = Trim(Integer.Parse(FldPositionTextBox.Text))
value = Trim(Integer.Parse(FldPositionTextBox.Text))
Select Case value
Case Is > 0 ' or Case 1 To 1000
value += 1
FldPositionTextBox.Text = value.ToString
If Me.FldPositionTextBox.Text = "1" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
If Me.FldPositionTextBox.Text = "2" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
If Me.FldPositionTextBox.Text = "3" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
If Me.FldPositionTextBox.Text = "4" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
If Me.FldPositionTextBox.Text = "5" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
If Me.FldPositionTextBox.Text = "6" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
If Me.FldPositionTextBox.Text = "7" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
If Me.FldPositionTextBox.Text = "8" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
If Me.FldPositionTextBox.Text = "9" Then Me.FldPositionTextBox.Text = "0" + Me.FldPositionTextBox.Text
End Select
End If
End If
Else
' else not checked
End If
If Me.CheckBox8.Checked = True Then ' Compartment
' Me.FldCompartmentTextBox.Text = mlngData8
If Me.CheckBox10.Checked = True Then
Me.FldCompartmentTextBox.Text = mlngData8 ' Compartment
Dim arg As Char = FldCompartmentTextBox.Text
If Char.IsLetter(arg) Then
Dim value As Integer = AscW(arg)
Select Case value
Case 65 To 89, 97 To 121
' value = System.Text.RegularExpressions.Regex.Replace(FldPositionTextBox.Text, "[^a-zA-Z0-9]", String.Empty)
FldCompartmentTextBox.Text = ChrW(value + 1).ToString
End Select
End If
If Char.IsNumber(arg) Then
' Dim value As Integer = CInt(FldCompartmentTextBox.Text)
Dim value As Integer = Integer.Parse(FldCompartmentTextBox.Text)
Select Case value
Case Is > 0 ' or Case 1 To 1000
value += 1
FldCompartmentTextBox.Text = value.ToString
If Me.FldCompartmentTextBox.Text = "1" Then FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
If Me.FldCompartmentTextBox.Text = "2" Then Me.FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
If Me.FldCompartmentTextBox.Text = "3" Then Me.FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
If Me.FldCompartmentTextBox.Text = "4" Then Me.FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
If Me.FldCompartmentTextBox.Text = "5" Then Me.FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
If Me.FldCompartmentTextBox.Text = "6" Then Me.FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
If Me.FldCompartmentTextBox.Text = "7" Then Me.FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
If Me.FldCompartmentTextBox.Text = "8" Then Me.FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
If Me.FldCompartmentTextBox.Text = "9" Then Me.FldCompartmentTextBox.Text = "0" + Me.FldCompartmentTextBox.Text
End Select
End If
End If
Else
' else not checked
' FldCompartmentTextBox.Clear()
End If
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you want to eliminate all characters except numbers, letters trim leading and trailing spaces and extra spaces
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Here's VB.Net and this example is very thorough.
http://www.dreamincode.net/code/snippet3423.htm
This article takes a fairly in-depth look at strings. Ideally you'd want to parse the string a number of ways. Looking for " " a space the ASCII characters for space, tab and return and then you'd want to also search for "\r", "\s", "\n" and "\t" you could of course use RegEx as well.
Here is a bunch of solid examples from Google with this search term:
http://www.google.com/search?q=vb.net+code+to+replace+all+space+and+tabs&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1&rlz=1I7GGLL_en#q=vb.net+code+to+replace+all+space+in+strings&hl=en&rls=com.microsoft:en-us&rlz=1I7GGLL_en&prmd=ivns&ei=PkZcTfr-M468sQOe_9zwAQ&start=0&sa=N&fp=cb921b9e247079c3