|
-
Feb 10th, 2004, 10:37 PM
#1
Thread Starter
Frenzied Member
add a space to every other character [RESOLVED]
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?
Last edited by Andy; Feb 11th, 2004 at 09:28 PM.
-
Feb 10th, 2004, 10:57 PM
#2
Sleep mode
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)
-
Feb 10th, 2004, 11:06 PM
#3
Thread Starter
Frenzied Member
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
-
Feb 10th, 2004, 11:35 PM
#4
Thread Starter
Frenzied Member
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?
-
Feb 11th, 2004, 12:10 AM
#5
Thread Starter
Frenzied Member
I came up with this instead of the function:
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
but it only does HALF of the text because of the step 2 I guess.
-
Feb 11th, 2004, 12:27 AM
#6
Thread Starter
Frenzied Member
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
this is what I'm after. Can't believe I figured it out by myself!!!
-
Feb 11th, 2004, 01:00 AM
#7
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.
Last edited by Edneeis; Feb 11th, 2004 at 11:12 AM.
-
Feb 11th, 2004, 07:15 AM
#8
Thread Starter
Frenzied Member
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
-
Feb 11th, 2004, 01:20 PM
#9
Sleep mode
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
I took it you want to do that with numbers . sry
-
Feb 12th, 2004, 09:55 PM
#10
PowerPoster
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)
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 13th, 2004, 10:24 AM
#11
Thread Starter
Frenzied Member
oops!! I closed this thread as resolved and forgot to post my code at how it got resolved!!!!
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!!!
-
Feb 13th, 2004, 10:56 AM
#12
PowerPoster
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
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|