Dracil Posted January 14, 2010 Posted January 14, 2010 If i have $obj = "Hello $Me" How can i grab "Hello" and "Me" from that string? Any advice?
bogQ Posted January 14, 2010 Posted January 14, 2010 (edited) $days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",") ;$days[1] contains "Sun" ... $days[7] contains "Sat" flag = 1, entire delimiter string is needed to mark the split Edited January 14, 2010 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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.
Dracil Posted January 14, 2010 Author Posted January 14, 2010 Ok that looks good so far, so if its $days = StringSplit("Hey man $aha", " $") MsgBox(0,"",$days[1]) MsgBox(0,"",$days[3]) It works, but the problem is it can end up without the " $" $days = StringSplit("Hey girl", " $") MsgBox(0,"",$days[1]) MsgBox(0,"",$days[3]) And that wont let me run it.
Hawkwing Posted January 14, 2010 Posted January 14, 2010 soooo.... $days[3] = "$" & $days[3] The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
somdcomputerguy Posted January 14, 2010 Posted January 14, 2010 (edited) $Me is already set somewhere, why StringSplit it out from somewhere else? Edited January 14, 2010 by snowmaker - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Dracil Posted January 14, 2010 Author Posted January 14, 2010 $days[3] = "$" & $days[3] Uh what ? $obj changes it can be $obj = "Hello $Me" $obj = "Hello $Doll" $obj = "Hello" When its just "Hello" it crashes with stringsplit
scriptjunkie Posted January 15, 2010 Posted January 15, 2010 You could use stringinstr to see if "$" is in the string.
somdcomputerguy Posted January 15, 2010 Posted January 15, 2010 (edited) If $obj = "Hello $Me" or "Hello $Whatever" already, why does that string need to be StringSplit out of itself and set to something else? Why not just use $obj, again? Edit: Does $obj always but only sometimes have "Hello"? If the string <> "Hello", or if it's more than 5 chars, or some other thing.., then put a StringSplit to it.. Edited January 15, 2010 by snowmaker - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Hawkwing Posted January 15, 2010 Posted January 15, 2010 Oh, I thought you wanted the "$" back on after the stringsplit. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
Dracil Posted January 15, 2010 Author Posted January 15, 2010 Well if the $obj is not only "hello" if its "hello $mia" i need to get into into to seperate strings. i need the "mia" in one and "hello" in one, the "hello" can also change u see.
Hawkwing Posted January 15, 2010 Posted January 15, 2010 StringRegExp might be the easiest way then. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
Dracil Posted January 15, 2010 Author Posted January 15, 2010 Can i use StringRegExp to get all data before " $" and then use it again to get everything after " $" and if there is no " $" it shud just return something empty right ?
Mison Posted January 15, 2010 Posted January 15, 2010 $obj changes it can be $obj = "Hello $Me" $obj = "Hello $Doll" $obj = "Hello" When its just "Hello" it crashes with stringsplit Check if StringSplit was successful: #include <array.au3> ; for _ArrayDisplay $obj = "Hello $Me" $result = StringSplit($obj," ") If @error Then $result = $obj If IsArray($result) Then _ArrayDisplay($result) Else MsgBox(0,"",$result) EndIf Hi ;)
jchd Posted January 15, 2010 Posted January 15, 2010 Does this work in all cases the way you need? #include <Array.au3> Local $str[6] = ["Hello$World!", "Hello$", "Hello", "$World!", "$", ""], $ret For $i = 0 To UBound($str) - 1 $ret = StringRegExp($str[$i], "([^$]*)\$?([^$]*)?", 1) _ArrayDisplay($ret, "Split of '" & $str[$i] & "'") Next This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Malkey Posted January 15, 2010 Posted January 15, 2010 (edited) Ok that looks good so far, so if its $days = StringSplit("Hey man $aha"," {:content:}quot;) MsgBox(0,"",$days[1]) MsgBox(0,"",$days[3]) It works, but the problem is it can end up without the " $") $days = StringSplit("Hey girl", " $") MsgBox(0,"",$days[1]) MsgBox(0,"",$days[3]) And that wont let me run it. For future reference, I direct your attention to the parameters of StringSplit in the help file. You are using "0", the default flag parameter, which is wrong, because you are using more than one character as the delimiter to mark the split/s in the string. #include <Array.au3> $days = StringSplit("Hey man $aha", " $", 3) _ArrayDisplay($days) Edit: Change the the automatic change of " $" to " {:content:}quot; back to " $" Edit2: And again. Edited January 15, 2010 by Malkey
Mison Posted January 15, 2010 Posted January 15, 2010 (edited) Also, for your future reference, if you are using more than one character(say "xy") with default flag, string will be splitted by the delimeter "x" OR "y". Example: #include <array.au3> $a = "111x222y333" $b = StringSplit($a,"xy") _ArrayDisplay($b) Edited January 15, 2010 by Mison Hi ;)
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