Inserting vbcrlf in a string

  • Thread starter Thread starter Drygast
  • Start date Start date
D

Drygast

I've got at form where I insert some information to a string ( oMed ) using
a inputbox.
I would like to alter the string so that a vbcrlf is inserted into the
string every 50 charachters or so.
How can I do this?

For exampel:
before: oMed = "the two towers will soon come to a theater near you!"
After: oMed= "The two towers will soon" & vbcrlf & "come to a theater near
you!"

Regards
/Drygast
 
Drygast said:
I've got at form where I insert some information to a string ( oMed )
using a inputbox.
I would like to alter the string so that a vbcrlf is inserted into
the string every 50 charachters or so.
How can I do this?

For exampel:
before: oMed = "the two towers will soon come to a theater near
you!"
After: oMed= "The two towers will soon" & vbcrlf & "come to a
theater near you!"

Dim sb As New System.Text.StringBuilder
Dim s As String = "the two towers will soon come to a theater near you!"
Dim i As Integer

For i = 0 To s.Length - 1 Step 20
sb.Append(Mid(s, i + 1, 20))
sb.Append(vbCrLf)
Next

sb.Length -= 2
MsgBox(sb.ToString)
 
Hi Drygast
I've got at form where I insert some information to a string ( oMed ) using
a inputbox.
I would like to alter the string so that a vbcrlf is inserted into the
string every 50 charachters or so.
How can I do this?

For exampel:
before: oMed = "the two towers will soon come to a theater near you!"
After: oMed= "The two towers will soon" & vbcrlf & "come to a theater near
you!"

This is with lines of 3 characters.

Dim strTest As New System.Text.StringBuilder
Dim oMed As String = "aaaaaaaaaaaaaaaabbbbbbbbbbbbccccccccccccddddddddddddd"
Dim id As Integer = 0
Do Until id > oMed.Length - 1
If id > oMed.Length - 4 Then
strTest.Append(oMed.Substring(id, oMed.Length - id))
Else
strTest.Append(oMed.Substring(id, 3) & vbCrLf)
End If
id += 3
Loop
Me.TextBox1.Text = strTest.ToString

I hope this helps a little bit?
Cor
 
Hi Armin,

And again we see an advantage from the Visual Basic functions against the
Net members.

(You don't have to test for the end length),

But we saw this some threads below too.

(And still I don't use them)

:-)

Cor

ps I always forget the step in a for, otherwise I would have done it basicly
the same as you but then with the substring.
 
Cor said:
And again we see an advantage from the Visual Basic functions against
the Net members.
:-)

(You don't have to test for the end length),

But we saw this some threads below too.

That's why I could still remember. ;-)
 
Back
Top