Jump to content
Sign in to follow this  

Q1) How to merge strings, each a part of the whole

Recommended Posts

Hey fellas, I got a couple questions. Hopefully someone can help me out a bit :">

Question #1:

How would I go about merging several strings? Normally the answer would be easy, but what if each of these strings is only a part of the whole and if one part of it already exists in another it should be overwritten. One could start at the beginning and cut off in the middle, another in the middle cut off at the end and one could just be the middle of the whole string. Take the following as an example.

$string1 = "1,2,3"

$string2 = "3,4,5"

$string3 = "2,3,4,5"

$string4 = "5,6,7"

therefore, the complete string is: "1,2,3,4,5,6,7"

The numbers in the string are ALWAYS in the same order, they just start and end at different places, therefore I need to merge them to get the complete string. I am puzzled at how to go about doing this :ph34r:.

Question #2

I thought I might aswell stick in another quicky question. Is there any other way than using "return" to exit a function, so the script will continue? Is using "return" the only method? I know it will work but just wanted to know if there is another way.

Edited by ravenfyre

Share this post

Link to post
Share on other sites

$STRING1 = "1,2,3"
$STRING2 = "3,4,5"
$STRING3 = "2,3,4,5"
$STRING4 = "5,6,7"


MsgBox(0, 'test', $TOTAL)

   $START = StringInStr($TSTRING, StringLeft($ISTRING, 1)) - 1
   If $START = -1 Then $START = StringLen($TSTRING)
   Return $TSTRING  
EndFunc  ;==>Merge

A "Func" ends with "Return" or when it reaches the "EndFunc" statement...

Edited by JdeB

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.

Share this post

Link to post
Share on other sites

A1) You should use stringsplit to split up the items by a comma and then parse each one to see if it has been used already.

$var1 = "5,2,4,7,9"
$var2 = "7,8,6,5,2"
$var3 = "9,6,5,8,3"
$str = $var1 & "," & $var2 $ "," & $var3
$arr = StringSplit($str, ",")
$newstr = ""
for $i = 0 to $arr[0]
   if not StringInStr($newstr, $arr[$i]) Then
      $newstr = $newstr & "," & $arr[$i]

EDIT: I see I have been preceeded.

Edited by this-is-me

Who else would I be?

Share this post

Link to post
Share on other sites

Ah, good info, thanks guys.

A2: EndFunc  :">


Doh! Didn't even consider using EndFunc. All those endless hours starring at my monitor trying to finish my script has fried my brain lol :ph34r:

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...