Sign in to follow this  
Followers 0
Emiel Wieldraaijer

Split a long string

9 posts in this topic

#1 ·  Posted (edited)

Hi,

Does someone know how to change the following

00000000000000000000000000000000 (this one has a variable length)

into

*************

*00000000*

*00000000*

*00000000*

*00000000*

*************

Thnx

Emiel

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites



Did you already try it yourself? Do you have some code we can review?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Or quick and dirty:

$iPartlen = 5
$sString = "000000000000000000000000000000000000000000000000000000000000000000000000"
$iPos = 1
While 1
    If $iPos >= StringLen($sString) Then Exitloop
    ConsoleWrite ("*" & StringMid($sString, $iPos, $iPartlen) & "*" & @CRLF)
    $iPos += $iPartlen
Wend

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No i did not have any code ..

i could not get my mind clear the find the solution for this

And now i see your code .. it's simple.. i need to get some sleep... maybe that will help :)

Thnx

Cheers


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

Good night :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here's a simple snippet I wrote a while back. It splits a string into equal length segments. Any remaining characters appear in the last array element.

#include <Array.au3>

Local $string = "1a2b3c4d5e6f7g8h9i" ; string to split
Local $iLimit = 5 ; length of each segment
Local $array = StringRegExp($string, "(?s).{1," & $iLimit & "}", 3) ; the magic

_ArrayDisplay($array)
Edited by czardas

Share this post


Link to post
Share on other sites

@Water

Thanks again.. really simple

@Czardas

Thanks also a nice example


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

Glad you like it :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This creates a long string, and then splits the long string.

Local $iPartlen = 8

; From  http://www.autoitscript.com/forum/index.php?showtopic=101594&view=findpost&p=722113
Local $sString = StringRegExpReplace(StringFormat("%" & ($iPartlen * 4) & "s", " "), ".", "0") ; = 32 "0"'s = "00000000000000000000000000000000"

ConsoleWrite("*************" & @LF & StringRegExpReplace($sString, "(.{" & $iPartlen & "})", "*\1*" & @LF) & "*************" & @CRLF)

#cs
Console output:-
*************
*00000000*
*00000000*
*00000000*
*00000000*
*************
#ce

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0