John117 Posted April 26, 2009 Share Posted April 26, 2009 (edited) Hey I need to store to variable the two words that appear in the result. -The sentence could be longer but will contain "is a type of" I do not need the origional string other than to get those two words. So any way will work as long as its $Variable1 is a type of $Variable2 Format. #include <String.au3> #include <Array.au3> $String = "Did you know that Species is a type of Class" _BreakDownString() Func _BreakDownString() If StringInStr($String, "is a type of") = True Then $array1 = _StringExplode($String, " ", 0) _ArrayDisplay($array1, "StringExplode 0") For $x = 0 to UBound($array1) - 4 If $array1[$x] = "is" And $array1[$x+1] = "a" And $array1[$x+2] = "type" And $array1[$x+3] = "of" Then $Variable1 = $array1[$x-1] $Variable2 = $array1[$x+4] EndIf Next ;$String = StringReplace($String, "is a type of", "") msgbox(0,"Result", $Variable1 & " " & $Variable2) EndIf EndFunc I am guessing there has to be a better way than what I came up with? Thanks. -look forward to learning more! Edit: Title Typo Edited April 26, 2009 by Hatcheda Link to comment Share on other sites More sharing options...
Authenticity Posted April 26, 2009 Share Posted April 26, 2009 Dim $sString = "Did you know that Species is a type of Class" Dim $sPattern = '(?i)(\w++) is a type of (\w++)' Dim $aMatch = StringRegExp($sString, $sPattern, 1) If IsArray($aMatch) And UBound($aMatch) > 1 Then _ ConsoleWrite('Variable name: ' & $aMatch[0] & @LF & 'Type name: ' & $aMatch[1] & @LF) Link to comment Share on other sites More sharing options...
John117 Posted April 26, 2009 Author Share Posted April 26, 2009 Dim $sString = "Did you know that Species is a type of Class" Dim $sPattern = '(?i)(\w++) is a type of (\w++)' Dim $aMatch = StringRegExp($sString, $sPattern, 1) If IsArray($aMatch) And UBound($aMatch) > 1 Then _ ConsoleWrite('Variable name: ' & $aMatch[0] & @LF & 'Type name: ' & $aMatch[1] & @LF) Thank you very much! I have made it along way with this tonight! 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