Is there anyway to get those big hollow boxes out of a string? Trim(string) doesnt work.
Any help is greatly appreciated!
Printable View
Is there anyway to get those big hollow boxes out of a string? Trim(string) doesnt work.
Any help is greatly appreciated!
I think they could be a Chr(13) or Chr(10), just check if the end of the string contain either one and then take it out of the string.
Sunny
Which big hollow box?
Is it one of the standard characters like the carriage return or line feed?
And does it happen every time?
Can you give an example?
Can you tell us where you experience this and what control contains this.
Can we have a code sample?
Code:Option Explicit
'replace function in VB6
'find an instance and replace it with another
' not sure what you want to get rid of
'this one gets rid of all spaces
Private Sub Form_Load()
Dim string1 As String, string2 As String
string1 = "my name is somewhere to be found!"
MsgBox string1
string2 = Replace(string1, " ", "")
MsgBox string2
End Sub
Here is the VB5 eqv. of Replace().
Code:Public Function Replace(sIn As String, sFind As String, sReplace As String, Optional nStart As Long = 1, Optional nCount As Long = -1, Optional bCompare As VbCompareMethod = vbBinaryCompare) As String
Dim nC As Long, nPos As Integer, sOut As String
sOut = sIn
nPos = InStr(nStart, sOut, sFind, bCompare)
If nPos = 0 Then GoTo EndFn:
Do
nC = nC + 1
sOut = Left(sOut, nPos - 1) & sReplace & _
Mid(sOut, nPos + Len(sFind))
If nCount <> -1 And nC >= nCount Then Exit Do
nPos = InStr(nStart, sOut, sFind, bCompare)
Loop While nPos > 0
EndFn:
Replace = sOut
End Function
Code that generates those line feed or return characters(dont know which).
Temp has extra of those up to 200 chars. I need to do this same thing(gets value from ini file) but with those damn return or line feed chars!Code:#!/usr/bin/perl
Public Function IniString(Heading As String, Key As String, File As String) As String
Dim ret As Long
Dim temp As String * 200
ret = GetPrivateProfileString(Heading, Key, File, temp, Len(temp), File)
If ret = 0 Then
Beep
Else
IniString = Trim(temp)
End If
End Function
Try this piece'o'code...
Enjoy!Code:Private Sub Form_Load()
Dim TestString As String
TestString = "This is a line " & vbTab & "with some 'hollow boxes'" & vbCrLf & " wich will be stripped soon..."
TestString = ETrim(TestString)
End Sub
Public Function ETrim(S As String) As String
'ETrim trims all "unknown chars" etc.. from a string
Dim T As Integer
Dim TmpS As String
TmpS = "" ' Clear Temporary String
For T = 1 To Len(S) ' Check all the in-string
If Asc(Mid(S, T, 1)) >= 32 Then TmpS = TmpS + Mid(S, T, 1) ' no weird stuff? Then add it to TmpS
Next T
ETrim = TmpS ' And return the value
End Function
Those Hollow boxes are NULL (0) bytes. try this:Quote:
Originally posted by Xero
Code that generates those line feed or return characters(dont know which).
Temp has extra of those up to 200 chars. I need to do this same thing(gets value from ini file) but with those damn return or line feed chars!Code:#!/usr/bin/perl
Public Function IniString(Heading As String, Key As String, File As String) As String
Dim ret As Long
Dim temp As String * 200
ret = GetPrivateProfileString(Heading, Key, File, temp, Len(temp), File)
If ret = 0 Then
Beep
Else
IniString = Trim(temp)
End If
End Function
And it'll work!Code:IniString = Trim(Left(temp, InStr(temp, Chr(0)) - 1))