ravenfyre Posted August 26, 2004 Share Posted August 26, 2004 (edited) 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 .Question #2I 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 August 26, 2004 by ravenfyre Link to comment Share on other sites More sharing options...
ezzetabi Posted August 26, 2004 Share Posted August 26, 2004 (edited) A2: EndFunc :"> Edited August 26, 2004 by ezzetabi Link to comment Share on other sites More sharing options...
Developers Jos Posted August 26, 2004 Developers Share Posted August 26, 2004 (edited) $STRING1 = "1,2,3" $STRING2 = "3,4,5" $STRING3 = "2,3,4,5" $STRING4 = "5,6,7" $TOTAL = $STRING1 $TOTAL = Merge($TOTAL, $STRING2) $TOTAL = Merge($TOTAL, $STRING3) $TOTAL = Merge($TOTAL, $STRING4) MsgBox(0, 'test', $TOTAL) Func Merge($TSTRING, $ISTRING) $START = StringInStr($TSTRING, StringLeft($ISTRING, 1)) - 1 If $START = -1 Then $START = StringLen($TSTRING) $TSTRING = StringLeft($TSTRING, $START) & $ISTRING Return $TSTRING EndFunc ;==>Merge A "Func" ends with "Return" or when it reaches the "EndFunc" statement... Edited August 26, 2004 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. Link to comment Share on other sites More sharing options...
this-is-me Posted August 26, 2004 Share Posted August 26, 2004 (edited) 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] EndIf next EDIT: I see I have been preceeded. Edited August 26, 2004 by this-is-me Who else would I be? Link to comment Share on other sites More sharing options...
ravenfyre Posted August 26, 2004 Author Share Posted August 26, 2004 Ah, good info, thanks guys. A2: EndFunc :"> <{POST_SNAPBACK}>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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now