Jump to content

_StringInsert ()


Recommended Posts

Hi,

with this command,how to put more than one positions to insert string ?

thanx

_StringInsert() only inserts in one position, but you could put it in a loop to do multiple positions:

$MyString = "12345678901234567890"
$Result = _StringMultiIns($MyString, " - ", "5,10,15")
MsgBox(64, "Result", $Result) ; Should be "12345 - 67890 - 12345 - 67890"

; Function _StringMultiIns($sString, $sInsert, $sPos)
;     Where:
;          $sString = String to be changed
;          $sInsert = String to insert
;          $sPos = String containing comma delimited positions to insert at (i.e. 3,23,34)
;               Note: All positions are in the unmodified original string, additional positions will be
;               offset so inserts still occur in the same relative position.
;     Returns modified string
Func _StringMultiIns($sString, $sInsert, $sPos)
     Local $OffsetPos = 0
     Local $aSplit = StringSplit($sPos, ",")
     For $s = 1 To $aString[0]
          $OffsetPos += $aString[$s]
          $sString = _StringInsert($sString, $sInsert, $OffsetPos)
     Next
     Return $sString
EndFunc

Cheers!

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

LOL I especially searched an other way that a loop,beacause it takes damn much time in my script,and much CPU usage too(a 1000x loop...):/

I look forward to seeing how you do this without any loop... should be very instructive! :P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I look forward to seeing how you do this without any loop... should be very instructive! :)

Here => MultiInsertString()

I made a function doing this:)

An evolution of simple stringinsert :nuke:

ps:thanx to PsaltyDS giving me an example :P

Edited by clearguy
Link to comment
Share on other sites

Here => MultiInsertString()

I made a function doing this:)

An evolution of simple stringinsert :nuke:

ps:thanx to PsaltyDS giving me an example :P

Bzzzt! I coun't no less than three loops! Thanks for playing! Carol has some nice parting gifts for you at the door, including the new board game version of our show! :)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

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