Sign in to follow this  
Followers 0
Shinku

need help on a string function?

9 posts in this topic

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

Share this post


Link to post
Share on other sites



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')

[center]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.[/center]

Share this post


Link to post
Share on other sites

ahahha smoke lets not confuse him with stringregexp :P

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

#6 ·  Posted (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)

thanks

Are 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 by 1905russell

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Shinku

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

"message: bladiebladieblah"

thats the real art here!

lol

8)


NEWHeader1.png

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  
Followers 0