SPLIT STRING according to length

pax
12-27-2004, 04:30 AM
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. :)

pax
12-28-2004, 02:23 AM
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)
:)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum