What represents a new line in a String? I thought it would be line feed, but it isn't...
So, what is it?
Printable View
What represents a new line in a String? I thought it would be line feed, but it isn't...
So, what is it?
chr$(13) & chr$(10)
or
vbCrlf
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
When I try using the InStr function to look for those characters in a string it does not find them!
here is a quick sample using VBcr, vblf and vbcrlf
option Explicit
private Sub Command1_Click()
Dim str, X
'str = "The quick Brown Fox" & vbCrLf & "Jumps over the lazy dog"
' either way will work
str = "The quick Brown Fox" & vbCr & vbLf & "Jumps over the lazy dog"
X = InStr(str, vbCrLf)
MsgBox X
End Sub
John G
option Explicit
private Sub Command1_Click()
Dim strString as string
strString = "blablabla" & Chr$(13) & Chr$(10) & "blablablabla"
MsgBox fnctFindIt(strString) 'will be 10
strString = "blablablablab" & vbCrLf & "blablablabla"
MsgBox fnctFindIt(strString) 'will be 14
End Sub
private Function fnctFindIt(byval strParm as string) as string
Dim intFoundPos as Integer
intFoundPos = InStr(1, strParm, Chr$(13) & Chr$(10), vbBinaryCompare)
If intFoundPos > 0 then
fnctFindIt = "Line feed and carriage return found starting at " & intFoundPos & " position"
else
fnctFindIt = "Line feed and carriage return NOT found"
End If
End Function
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.