Hi
I have a string with 300 character and y have to divide in 75 so i can get 4 line off 75 character
so i can do this
Hi
I have a string with 300 character and y have to divide in 75 so i can get 4 line off 75 character
so i can do this
use LEFT/RIGHT and MID functions
Dim s, s1 As String
s1 = Your_Original_String
For c As Integer = 0 to 3
s = s + Left(s1, 75) +EndOfLine
s1 = Right(s1, (Len(s1) - 75))
Next
something like that may work
ok
thanks
That’s the function I use:
[code]Function FormatInBlocks(DNA as string, NumberOfBlocksPerLine as integer, Blocksize as integer, BlockSeparator as string) As String
Dim m As MemoryBlock = DNA
Dim inpos As Integer = 0
Dim outpos As Integer = 0
Dim maxpos As Integer = m.Size - 1
Dim NumberOfBlocksInLine as integer = 0
dim OutputMB as new MemoryBlock( maxpos + Floor( (maxpos - 1) / Blocksize ) + 2 )
if maxpos = -1 then // empty string
return ""
else
for inpos = 0 to maxpos // 0 1 2 3
// is a block full? inpos starts at 0 so need to check (inpos + 1) for Mod to work
if (inpos + 1) Mod Blocksize = 0 then // last position of block, so ...
OutputMB.Byte( outpos ) = m.Byte( inpos ) // add the character
outpos = outpos + 1 // increase outpos
NumberOfBlocksInLine = NumberOfBlocksInLine + 1 // increase the NumberOfBlocksInLine by one
// do we have all blocks in the line?
if NumberOfBlocksInLine = NumberOfBlocksPerLine then // yes, so ...
OutputMB.Byte( outpos ) = 13 // add return ??? will this work on Windows? Might have to increase MemoryBlock ...
NumberOfBlocksInLine = 0 // set NumberOfBlocksInLine back to 0
else
OutputMB.Byte( outpos ) = Asc( BlockSeparator ) // add separator
end if
else // block is not full, so just add character
OutputMB.Byte( outpos ) = m.Byte( inpos )
end if
outpos = outpos + 1 // go to next outpos
next
return OutputMB.StringValue( 0, outpos, Encodings.ASCII )
end if[/code]
This should do it!
Dim re As New RegEx
Dim resultString as String
Dim inputString as String // Your string with 300 chars.
re.SearchPattern = ".{1,75}"
re.ReplacementPattern = "$&\
"
re.Options.ReplaceAllMatches = True
resultString = re.Replace(inputString)
Tried it in RexExRX and it should result in this:
Albin,
you just re-confirmed my faith in Regex… nice job!
RegEx is like VooDoo… It is magical and sometimes you just cant explain it.
Dave was right
left right & mid are more than adequate
regex is overkill
Like using a sledgehammer to crack peanuts
[quote=128973:@Norman Palardy]Dave was right
left right & mid are more than adequate
regex is overkill
Like using a sledgehammer to crack peanuts[/quote]
Heh, sledgehammer? Totally inefficient. We need something bigger for those peanuts. Just kidding
I know Daves suggestion is enough. I only showed yet another way of achieving the same result
I follow the Looney Tunes method of programming. If a sledgehammer is overkill - drop an anvil on it.
Alexis may need more than a simple mechanical cut to 75 characters. Usually, this kind of case rather calls for line wrap.
Considering he stated quite simply
[quote=128645:@Alexis Colon Lugo]Hi
I have a string with 300 character and y have to divide in 75 so i can get 4 line off 75 character
[/quote]
Would seem that anything else is simply supposition.
If he needs to split on word boundaries that WOULD be very different - but he didn’t ask for that.