Jump to content

stringsplit according to length


t0ddie
 Share

Recommended Posts

i want to split a string according to length.

I want to split this string into an array of strings that are 128 characters or less each.

Dim $aRecords
$linelimit = 128


If Not _FileReadToArray("test.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

For $x = 1 to $aRecords[0]
    $line = StringLen($aRecords[$x]
    If $line > $linelimit Then
        $lines = StringSplit($aRecords[$x],heres the trouble area)
endif
Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

@t0ddie

Perhaps this : (not tested)

StringSplit($aRecords[$x], StringLeft($aRecords[$x], $line))

Edit : if the line lenght is 128 so you cant split it every 128 caracters, right ? :)

$firstpart=StringLeft($aRecords[$x],128)

$second = StringTrimLeft($aRecords[$x], 128)

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

@t0ddie

Perhaps this : (not tested)

StringSplit($aRecords[$x], StringLeft($aRecords[$x], $line))

Edit : if the line lenght is 128 so you cant split it every 128 caracters, right ? :)

$firstpart=StringLeft($aRecords[$x],128)

$second = StringTrimLeft($aRecords[$x], 128)

Cheers, FireFox.

i was thinking about that but it would be nice to have the functionality added to stringsplit.

oh well, i guess it aint pretty but it should work.

i will test

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

@t0ddie

I think its possible to split with caracters but i dont know that for the moment :)

$string = StringLeft($aRecords[$x], $line)

While 1
$trim = StringTrimLeft($string, $line)
If @error then exitloop
MsgBox(64, "string split", $trim)
$string = $trim
WEnd

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

i was thinking about that but it would be nice to have the functionality added to stringsplit.

oh well, i guess it aint pretty but it should work.

i will test

actually I am running into all kinds of issues.

like...

i wont know in advance the length of the line, so i will need to create an array

there must be a more simple way to do this

sudden thought

are wildcards supported for delimiters?

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

here's a stab at it...

#include <Array.au3>
#include <File.au3>

Dim $aRecords
$linelimit = 128

If Not _FileReadToArray("test.txt", $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

For $x = 1 To $aRecords[0]
    $line = StringLen($aRecords[$x])

    If StringLen($line) > $linelimit Then

        While StringLen($line) > $linelimit

            $nline = StringLeft($aRecords[$x], $linelimit)

            _ArrayAdd($aRecords, $nline); or do something else???

            $aRecords[$x] = StringTrimLeft($aRecords[$x], $linelimit)

            $line = StringLen($aRecords[$x])
        WEnd

    EndIf
Next

*** NOT TESTED ***

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

lol...

I just tried to help "handle" the 128 chr string and keep it within the array

... But did this help????? no reply from t0ddie noted

8)

You didn't really expect him to make sense and or reply with a thanks did you?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

size doesn't matter :)

Simplified example splitting every 10th character (I leave the split function out of it but if real split needed split on CRLF)

$myLine="012345678901234567890123456789012345"
$myNewline=StringRegExpReplace($myLine, ".{1,10}", "$0" & @CRLF)
consolewrite($myNewline)
Link to comment
Share on other sites

screw you, you assumptuous impatient bastards!

I had to go to work. I am back now and will reply when I am good and damn ready.

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

  • Moderators

screw you, you assumptuous impatient bastards!

I had to go to work. I am back now and will reply when I am good and damn ready.

Need a dictionary?

Our "assumptions" are merely based on past facts.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Need a dictionary?

Our "assumptions" are merely based on past facts.

I have always thanked the few people that help me here, and returned whatever bullshit has been thrown at me from the rest of the users. nothing has changed. thanks for helping guys, and as for the crude comments from the rest, blow me.

I decided to use a loop instead of an array...

this was my original unbuilt idea... but i thought it was unnecissary if i could find a better means...

alas, it has been built.

untested... but it should work.

Dim $aRecords
$linelimit = 128
$len = 0

If Not _FileReadToArray("murel_01.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

For $x = 1 to $aRecords[0]
    $len = StringLen($aRecords[$x])
    If $len > $linelimit Then
Do
    $bRecords = StringTrimRight($aRecords[$x],$len - $linelimit)
    $aRecords[$x] = StringTrimLeft($aRecords[$x],$linelimit)
    $len = StringLen($aRecords[$x])
    ClipPut($bRecords)
    write()
Until $len <= $linelimit

Else
    ClipPut($aRecords[$x])
    write()
    EndIf
next

I have had to do this type of thing before... just wanted a better way.

-T0ddie

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

  • Developers

screw you, you assumptuous impatient bastards!

I had to go to work. I am back now and will reply when I am good and damn ready.

I am even more impatient with you!

You better keep this attitude to yourself or better move on to another forum.

* click *

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...