Jump to content
Sign in to follow this  
COD3369

Split string at every given characters

Recommended Posts

COD3369

#include<string.au3>
#include <File.au3>

$in = ""
Dim $string = "687474703a2f2f7777772e6175746f69747363726970742e636f6d2f666f72756d2f746f7069632f36333933372d686f772d746f2d73706c69742d612d737472696e672d61667465722d342d636861726163746572732f", $result

$aNumber = StringRegExp($string, "\N{15}", 3)

For $i = 0 To UBound($aNumber) - 1
    $result &= "Global "&"$vVar" &$i & "= " & """" & $aNumber[$i]&"""" & @CRLF
Next
$result = StringTrimRight($result, 1)
FileWrite ( @scriptdir & "\code.au3" , $result )

 its working good splitting the line at every 15 chars but its not writing the last 9 characters to file 

46572732f

Output of code.au3

Global $vVar0= "687474703a2f2f7"
Global $vVar1= "777772e6175746f"
Global $vVar2= "697473637269707"
Global $vVar3= "42e636f6d2f666f"
Global $vVar4= "72756d2f746f706"
Global $vVar5= "9632f3633393337"
Global $vVar6= "2d686f772d746f2"
Global $vVar7= "d73706c69742d61"
Global $vVar8= "2d737472696e672"
Global $vVar9= "d61667465722d34"
Global $vVar10= "2d6368617261637"

Where am wrong guys I got this script from some where and I just input my string and change the to 15

:x  :x  :x  :x

Share this post


Link to post
Share on other sites
johnmcloud

#include <Array.au3> ;just for test

Local $sString = "687474703a2f2f7777772e6175746f69747363726970742e636f6d2f666f72756d2f746f7069632f36333933372d686f772d746f2d73706c69742d612d737472696e672d61667465722d342d636861726163746572732f"
;Dim is deprecated!
Local $sEvery = 15

$sFinal = StringSplit(StringRegExpReplace($sString, "\w{" & $sEvery & "}", "\0|"),"|")
_ArrayDisplay($sFinal, "Johnmcloud Test Code")

Share this post


Link to post
Share on other sites
bogQ

StringRegExp($string, ".{1,15}", 3)

or

StringRegExp($string, "(?s).{1,15}", 3)

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

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  

×