Jump to content
Sign in to follow this  
t0ddie

stringsplit according to length

Recommended Posts

t0ddie

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.

Share this post


Link to post
Share on other sites
FireFox

@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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
t0ddie

@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.

Share this post


Link to post
Share on other sites
FireFox

@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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
t0ddie

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.

Share this post


Link to post
Share on other sites
Valuater

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

Share this post


Link to post
Share on other sites
FireFox

@Valuater

I dont know if my script or your script work but mine is smaller :)

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Valuater

@Valuater

I dont know if my script or your script work but mine is smaller :)

Cheers, FireFox.

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)


NEWHeader1.png

Share this post


Link to post
Share on other sites
trancexx

I've heard people saying: "Mine is bigger than yours!"

You are weird :)


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
Valuater

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

for sure...No!!!

with as much as he knows about Autoit and with as many posts he has made, the OP example code has errors in it too!

lol

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
junkew

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)

Share this post


Link to post
Share on other sites
t0ddie

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.

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
t0ddie

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.

Share this post


Link to post
Share on other sites
FireFox

@Smoke_N

:) sorry if there are errors in my script... if there is scite for ipod i will take it...

what about for a page where you can write your code with colors and check for errors ?

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×