what's the best way to add a space every other character in a text file? The end result I want is to take this: 123456 7890 and turn it into this: 1 2 3 4 5 6 7 8 9 0. This also adds a space to a space.
any ideas?
Printable View
what's the best way to add a space every other character in a text file? The end result I want is to take this: 123456 7890 and turn it into this: 1 2 3 4 5 6 7 8 9 0. This also adds a space to a space.
any ideas?
That's one way ,
VB Code:
Dim str1 As String = "1234567890" Dim str2 As String str1.ToCharArray() For i As Integer = 0 To str1.Length str2 += Str(i) Next MessageBox.Show(str2)
all that code does is replace text with a sequential number run. that's on the track though. I need to take ANY typed text and space it out.
andy becomes a n d y
so far, I have made a function that uses a select case and compares the alphabet like this:
"s" becomes "s "
how can I use the streamreader to send each character to the bunction?
I came up with this instead of the function:
but it only does HALF of the text because of the step 2 I guess.Code:Dim length As Integer = txtMessage.Text.Length
Dim character As Integer
For character = 0 To length Step 2
txtMessage.Text = txtMessage.Text.Insert(character, " ")
Next
this is what I'm after. Can't believe I figured it out by myself!!!Code:'put a space betweeen every other character
Dim length As Integer = txtMessage.Text.Length
Dim character As Integer = 0
For character = 0 To (length * 2) Step 2
txtMessage.Text = txtMessage.Text.Insert(character, " ")
Next
You could also do this:
VB Code:
'put a space betweeen every other character Dim length As Integer = txtMessage.Text.Length Dim character As Integer = 0 For character = length To 0 Step -1 txtMessage.Text = txtMessage.Text.Insert(character, " ") Next
EDIT: That was my bad you'd have to step through backwards to use length.
Quote:
Originally posted by Edneeis
You could also do this:
VB Code:
'put a space betweeen every other character Dim length As Integer = txtMessage.Text.Length Dim character As Integer = 0 For character = 0 To length txtMessage.Text = txtMessage.Text.Insert(character, " ") Next
that's actualy what I had at first I think but it doesn't skip every other character. it places spaces at the beginning of the text equal to the length.
I had it to where it would do exactly HALF the text and then, just as a shot-in-the-dark, decided to double the LENGTH variable. It worked. I only wish I figured that out in my head instead of playing battleship with it LOL
I took it you want to do that with numbers . sryQuote:
Originally posted by thephantom
all that code does is replace text with a sequential number run. that's on the track though. I need to take ANY typed text and space it out.
andy becomes a n d y
:D
Hi,
"
After watching you guys run round in circles are you sure you have resolved the original question? I think the code you finished up with still puts a space after a space, which at one stage was not acceptable.
Try:
Dim str1 As String = "12345 67890"
Dim str2 As String
Dim x, y As Integer
y = 1
str2 = ""
For x = 0 To Len(str1) - 1
If Mid(str1, y, 1) <> " " Then
str2 += Mid(str1, y, 1) + " "
End If
y = y + 1
Next
MessageBox.Show(str2)
oops!! I closed this thread as resolved and forgot to post my code at how it got resolved!!!!:blush:
VB Code:
'put a space betweeen every other character Dim length As Integer = txtMessage.Text.Length Dim character As Integer = 0 'space-out the message For character = 0 To (length * 2) Step 2 txtMessage.Text = txtMessage.Text.Insert(character, " ") Next
this DOES put a space after a space, but that's necessary to still be able to read the string.
the purpose of this code was to take an email message, space the strings and by-pass a spam-guard program that was falsely rejecting my emails. works like a charm!!!:bigyello:
Hi,
"'put a space betweeen every other character
Dim length As Integer = txtMessage.Text.Length
Dim character As Integer = 0
'space-out the message
For character = 0 To (length * 2) Step 2
txtMessage.Text = txtMessage.Text.Insert(character, " ")
Next"
If you do not want leading or trailing spaces
For character = 1 To (length * 2 - 2) Step 2
txt2.Text = txt2.Text.Insert(character, " ")
Next