Hello every one,
I have a string with multi lines, i need to split the string into arrary accodring to the length each line is 80 char can i do that using SPLIT FUNCITON
THANKS
Iceplug
12-27-2004, 09:50 AM
Well, you *can* do it with the split function... you'd just have to go into the string manually, and add some kind of delimiter between every few characters.
But, it would be much easier to just use a For Loop or a Do Loop, along with the Substring function.
You'd have something like
Idx = 0
For LV = 0 To YourString.Length - 1 Step ChunkSize
'loop through the characters in the string, jumping to each chunk.
arrary(Idx) = YourString.Substring(LV, ChunkSize)
'get the chunk containing chunksize's number of character's
Idx += 1
'move to the next index.
Next
If you want to split the string at the Newline character, then you can
.Replace(Environment.Newline, "ÿ")
and then split it at the "ÿ". The ÿ should represent a character that does not appear in the string. :)
thank you,
using for or while loop, we have to know the length of the array first.is that ok
wayneph
12-28-2004, 07:24 AM
thank you,
using for or while loop, we have to know the length of the array first.is that ok
you wouldn't have to know the array size. you could always just use an ArrayList for building. Then you can add items when ever you want regardless of size.
If you don't like the ArrayList you can calculate the needed size by dividing the String's Length by Chunk Size and Redimming the array to the needed size before you get into your loop.
Iceplug
12-28-2004, 07:38 AM
If you wanted to know the length of the array, it is
Math.Ceiling(YourString.Length / ChunkSize)
:)