Shinku Posted December 20, 2006 Posted December 20, 2006 can someone help me on this? i was a bit looking tru the help part of autoit but i couldn't get wiser on it. what i want to do is getting a part out of a string, example: "This is a string message. blahblah blah blah" and i want to get out the part "string message", and the search key would be "string" only. so that if u search for 'string' you would get 'string message' out "This is a string message. blahblah blah blah" (it doesnt matter if the dot comes too) thanks
Moderators SmOke_N Posted December 20, 2006 Moderators Posted December 20, 2006 Do you just want the next word after string, is that what you are trying to say? #include <array.au3> $sString = "This is a string message. blahblah blah blah" $sToFind = 'string' $aArray = StringRegExp($sString, '(?s)(?i)' & $sToFind & '\s+([0-9A-Za-z\-\_]+)', 3) _ArrayDisplay($aArray, 'Strings found') Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Thatsgreat2345 Posted December 20, 2006 Posted December 20, 2006 ahahha smoke lets not confuse him with stringregexp here are some simpler string functions to understand $var = "Here Is A String Message: This Is The String Message"; the string $string = StringSplit($var,":");;; splits at the : and creats an array so $string[1] would be Here is a string message MsgBox(0,'',$string[2]) ;$strign[2] would the This is the string message $search = "String Message:" MsgBox(0,'',StringTrimLeft($var,StringInStr($var,$search) + StringLen($search) - 1)) ;msgbox shows the end result ;stringtrimleft trims the string so many places from the left ;$var is what your trimming ;StringInStr gets the start place of a search string ;+ stringlen of the search minus 1 will tell it to trim the rest of the search since StrinInstr only returns the first place
Shinku Posted December 20, 2006 Author Posted December 20, 2006 hmm kinda nice but not the thing that i am looking for. I am making a small chat program in autoit, it works a bit but some information doesnt have to be viewable. example what would be sent: host: 192.168.1.100 nickname: anickname defaultcolor: red message: bladiebladieblah the problems are: this will be sent as 1 string. (well u show me something which can make parts, since it works with a chr() as an enter... dont know which one it was.) anyway the onlything that has to be filtered are nickname and message ofcourse "message:" and "nickname:" should not be inserted. so i need to get the information from "message:" and "nickname:". once this process has been completed the following message will be added in the chat: anickname : bladiebladieblah so i need to get the nickname aswell the message out of the string hopefully it makes a bit clear
mikehunt114 Posted December 20, 2006 Posted December 20, 2006 How about something like: #include <String.au3> $nick = _StringBetween($msg, "nickname: ", "default") $nick = StringTrimRight($nick, 7) $message = StringMid($msg, "message: ") $message = StringTrimLeft($message, 9) MsgBox(0, "Chat message", "nick: " & $nick & @CRLF & "message: " & $message) IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
1905russell Posted December 20, 2006 Posted December 20, 2006 (edited) so that if u search for 'string' you would get 'string message' out "This is a string message. blahblah blah blah" (it doesnt matter if the dot comes too) thanksAre you looking for a word and if you find it you want to display that word and the next word? Try this $sString = "This is a string message. blahblah blah blah"; the string $sSearch = "string" If StringInStr($sString,$sSearch)> 0 then $sString = StringMid($sString,StringInStr($sString,$sSearch)+Stringlen($sSearch)+1,Stringlen($sString)) $sNextWord = StringMid($sString, 1,StringInStr($sString," ")) $sString = $sSearch &" "& $sNextWord MsgBox(0,'',$sString) Endif Edited December 20, 2006 by 1905russell
Shinku Posted December 20, 2006 Author Posted December 20, 2006 (edited) if i look at the code i think that will do thanks for your fast reply. I'll try it out later but if i look at the codes it seems those will work with it thanks again Edit: i'll try both and decide which one is best Edited December 20, 2006 by Shinku
Moderators SmOke_N Posted December 20, 2006 Moderators Posted December 20, 2006 (edited) $sString = "host: 192.168.1.100" & @CRLF & _ "nickname: anickname" & @CRLF & _ "defaultcolor: red" & @CRLF & _ "message: bladiebladieblah" MsgBox(64, 'Info', _SREReturnInfo($sString)) Func _SREReturnInfo($sString) Local $aNick = StringRegExp($sString, '(?s)(?i)nickname\:\s+([0-9A-Za-z\-\_]+)', 3) Local $aMessage = StringRegExp($sString, '(?s)(?i)message\:\s+([0-9A-Za-z\-\_]+)', 3) Local $sHold = '' For $iCC = 0 To UBound($aNick) - 1 If IsArray($aNick) And IsArray($aMessage) Then $sHold &= $aNick[$iCC] & @CRLF & 'Said: ' & $aMessage[$iCC] & @CRLF EndIf Next Return StringTrimRight($sHold, 2) EndFuncoÝ÷ ØGb´Z½éè×ü¨º¹²Æ yìmzwl¥«-¶¥wºÛaÉÉÚ"µ«0zYmÁæ¤yÛazg¬±¨I-¡©e£ ®Ø©ì(ÛºÚ"µÍÚ[ÛYH Ø^K]LÉÝÂÌÍÜÔÝ[ÈH ][ÝÚÜÝNLMKL ][ÝÈ [ÈÔ [ÈÂBI][ÝÛXÚÛ[YN[XÚÛ[YI][ÝÈ [ÈÔ [ÈÂBI][ÝÙY][ÛÛÜY ][ÝÈ [ÈÔ [ÈÂBI][ÝÛYÜØYÙNYYXYYXZ[YYXYYXZ ][ÝÂÙÐÞ ÌÎNÒ[ÉÌÎNËÔÔT][Ê ÌÍÜÔÝ[ÊJB[ÈÔÔT][Ê ÌÍÜÔÝ[ÊBSØØ[ ÌÍØSXÚÈHÝ[ÔYÑ^ ÌÍÜÔÝ[Ë ÌÎNÊÜÊJÚJ[XÚÛ[YIÌLÎÌLÜÊÊÌNPKVK^ÌLËIÌL××JÊIÌÎNËÊBSØØ[ ÌÍØSYÜØYÙHHÝ[ÔYÑ^ ÌÍÜÔÝ[Ë ÌÎNÊÜÊJÚJ[YÜØYÙIÌLÎÌLÜÊÊÊJ ÌLÜ ÌLÛ ÌÍÊIÌÎNËÊBSØØ[ ÌÍÜÒÛH ÌÎNÉÌÎNÂQÜ ÌÍÚPÐÈHÈPÝ[ ÌÍØSXÚÊHHBBRYÐ^J ÌÍØSXÚÊH[Ð^J ÌÍØSYÜØYÙJH[BBIÌÍÜÒÛ [ÏH ÌÍØSXÚÖÉÌÍÚPÐ×H [ÈÔ [È ÌÎNÔØZY ÌÎNÈ [È ÌÍØSYÜØYÙVÉÌÍÚPÐ×H [ÈÔBQ[YS^T]Ý[Õ[TYÚ ÌÍÜÒÛB[[ Edited December 20, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Valuater Posted December 20, 2006 Posted December 20, 2006 "message: bladiebladieblah" thats the real art here! lol 8)
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