-
I have a some text fields which I am using to populate a listview box, but I can't arbirtrarily limit the maxt no of characters for any given entry.
What I intend to do is have it take any words that would not fit on one line onto the next line.
I'm kind of at a loss as I have never really had to do any string manipulation in VB before, but as I see it there are two things I need to do. I know beforehand how many lines I will need for a given string, as well as how many characters can fit on each line.
For example, if I had a 50 character string and could fit 35 characters per line, I would go to character 35 and work backwards until the first space, splitting the string there.
What I need to know is
a) is there any kind of a function to split a string into two or more smaller strings?
b) how do I manipulate a string character by character?
also if you happen to know the ascii code for a blank space that would be most appreciated.
-
<?>
Ascii Character = 32
If your string is 55 and you want 30 of it
myNewString = Left(myOldstring,30)
MyOtherEnd = Right(myoldstring,25)
Check out MidString and InStr functions
-
Thanks alot... now that I have that part I just need to know how you can manipulate s string character by character.
-
The following is a very simple example of going through a string one position at a time.
Code:
Private Sub Command1_Click()
Dim strTest As String
Dim intLength
Dim x As Integer
strTest = "This is a test string"
intLength = Len(strTest)
For x = 1 To intLength
Debug.Print Mid(strTest, x, 1)
Next x
End Sub
-
Strings
Dont know if this is what you want...
Dim strTest as String
strTest = "bla bla....."
If len(strTest) > 35 Then
strTest = Mid(strTest, 1, inStr(1,strTest, " "))
End if
/Smirre
-
<?>
slight addition to jbart's code.
Code:
Manipulation:
Private Sub Command1_Click()
Dim strTest As String
Dim intLength
Dim x As Integer
strTest = "This is a test string"
intLength = Len(strTest)
'change all i to M
For x = 1 To intLength
If Mid(strTest, x, 1) = "i" Then Mid(strTest, x, 1) = "M"
Next x
MsgBox strTest
End Sub