Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove CRLF and non-printable Chrs

Status
Not open for further replies.

NW

Programmer
Feb 3, 2000
61
0
0
GB
I have allow my users to capture comments in multi line text box and data keyed in this box get stored in a ‘memo’ field of a MS FoxPro table.
Is there a way to remove any crlf & any other non-printable chrs when reading this data back for reporting purpose?
Thanks
 
Try this....

The Replace function puts a space in for each CrLf. If you wanted to look for other non-printing charactars I think you'd just have to repeat the Replace for as many things as you want to look for

=====================================================
Option Explicit
Dim MyString1 As String
Dim MyString2 As String

Private Sub Form_Load()
'needs a multiline textbox called MyText
MyText = "Line1" & vbCrLf & "Line2" & vbCrLf & "Line3"
End Sub

Private Sub CommandShow_Click()
MyString1 = MyText
MyString2 = Replace(MyText, vbCrLf, " ")
Debug.Print Now
Debug.Print MyString1
Debug.Print MyString2
'MyString1 shows as many lines in debug
'MyString2 shows as only one line
End Sub Jim Brown,
Johannesburg,
South Africa.
My time is GMT+2
 
you might want to use regular expressions...

Code:
Option Explicit

Private Sub Command1_Click()
  Dim MyText As String
  Dim MyString1 As String
  Dim MyString2 As String
  Dim oREGEXP As RegExp
  
  Set oREGEXP = New RegExp
  
  MyText = "askdf" & Chr$(0) & _
           "aklsj" & vbLf & _
           "asbsdl" & Chr$(7) & _
           "aklsj" & vbCr & _
           "jkfad" & Chr$(9) & _
           "aklsj" & vbCrLf & _
           "dfhas"
  MyString1 = MyText
  With oREGEXP
    .Pattern = "[^ -~]"
    .Global = True
    MyString2 = .Replace(MyText, " ")
  End With
  Set oREGEXP = Nothing
  Debug.Print ">>>", Now
  Debug.Print ">>>", MyString1
  Debug.Print ">>>", MyString2
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top