mlupino
asked on
Determine a space character in a string
I would like to write a statement that does the following but I am having alot of trouble so all the help is appreciated.
The statement will:
take a string of (x character's) size to be determined by running program from a variable (such as Description)
break it down into 40 character segments
Reverse from 40 to a space ??? I am unsure on how to do that.
Print the number of characters from 1 to the character with a space.
Be contained in a loop so that I can pick up from the space and pick up another 40 characters.
Any help is greatly appreciated.
The statement will:
take a string of (x character's) size to be determined by running program from a variable (such as Description)
break it down into 40 character segments
Reverse from 40 to a space ??? I am unsure on how to do that.
Print the number of characters from 1 to the character with a space.
Be contained in a loop so that I can pick up from the space and pick up another 40 characters.
Any help is greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you Roger.
its been awhile since I programmed. I wanted to see if I could handle this task internally at my job, I spent all day trying out different types of loops.... (Do, Do While) and For, Next and wasn't making a dent.
its been awhile since I programmed. I wanted to see if I could handle this task internally at my job, I spent all day trying out different types of loops.... (Do, Do While) and For, Next and wasn't making a dent.
ASKER
I am having some trouble validating the code is working OK. It is probably me. I wanted to test it under a different condition, by adding a textbox1.text output to each broken string. I think seeing that may help me. I created six different textboxs from textbox1.text to textbox6.text to represent a maximum of 240 characters entered in as input. Would you be able to show me how to output the result of the split strings to text boxes. Any help would be appreciated. If you'd like i can open another question on the topic so you can get additional points.
The simplest way to test is to use a single TextBox with its .MultiLine property set to True and then use code like.
<myTextBox>.Text = SetLineLength(<TestText>, 40)
where myTextBox is the name of your textbox and TestText is the string you want breaking up.
If you want to put each line in a spearate textbox it becomes more complicated. Basically you need to split up the string that is returned by the function
Dim newlines() As String = Regex.Split(SetLineLength( <TestText> , 40), vbCrLf)
and then put each element of that newline array into one of the textboxes
TextBox0.Text = newlines(0)
TextBox1.Text = newlines(1)
'etc
That's easy enough, hard-coding. But the complications come in (a) that in real life you won't know how many elements there will be in the array and (b) that there is no direct method of coding the equivalence
TextBox? = newlines(?)
where ? represents an index number. If you want to go down that latter line I think a new question would be appropriate as it's really a different topic from that of splitting up the string.
Roger
<myTextBox>.Text = SetLineLength(<TestText>, 40)
where myTextBox is the name of your textbox and TestText is the string you want breaking up.
If you want to put each line in a spearate textbox it becomes more complicated. Basically you need to split up the string that is returned by the function
Dim newlines() As String = Regex.Split(SetLineLength(
and then put each element of that newline array into one of the textboxes
TextBox0.Text = newlines(0)
TextBox1.Text = newlines(1)
'etc
That's easy enough, hard-coding. But the complications come in (a) that in real life you won't know how many elements there will be in the array and (b) that there is no direct method of coding the equivalence
TextBox? = newlines(?)
where ? represents an index number. If you want to go down that latter line I think a new question would be appropriate as it's really a different topic from that of splitting up the string.
Roger
http://msdn2.microsoft.com/en-us/library/d93tkzah.aspx
if you just want to split the string at the spaces then you can use string.split function
http://msdn2.microsoft.com/en-us/library/system.string.split(VS.71).aspx