Jump to content

Andreu

Active Members
  • Posts

    56
  • Joined

  • Last visited

Community Answers

  1. Andreu's post in Javascript Substr equivalent was marked as the answer   
    This is written assuming no prior knowledge of AutoIt. If you aren't new, then... Simply, your answer is StringMid(). (Though, if your data is that consistent, looking into StringRegExp() would suit your needs more effectively, judging by what I assume you plan "todo" next. )
    Example of Newbie way to go about it:
    $str="Hello world A {@CRLF} Hello Universe B {@CRLF} Hello Earth C {@CRLF}"; Original String $param="Universe"; Substring $pos = StringInStr($str, $param) + StringLen($param) + 1; Where the substring starts $end = StringInStr($str, " ", "", 1, $pos); The first space after the substring $Final = StringMid($str, $pos, $end - $pos); Extracts it from the middle MsgBox (0, "Done", "Result Text: " & $Final); Yea... You can make this a whole lot shorter, condensing it down to just a one liner... But this is intended to be easier to read.
    Edit:
    Just noticed in your post you stated you wanted to pass "Universe" to a function... Here. 
    (This one will let you put Earth, World, Universe... etc.)

     
    $str = "Hello world A {@CRLF} Hello Universe B {@CRLF} Hello Earth C {@CRLF}"; Original String MsgBox (0, "Search Results", _Search(InputBox("Search Prompt", "What would you like to search for?", "Universe"))); Rcv the input, pass it to the function, display result Func _Search($param) $pos = StringInStr($str, $param) + StringLen($param) + 1; Where the substring starts $end = StringInStr($str, " ", "", 1, StringInStr($str, $param) + StringLen($param) + 1); The first space after the substring Return StringMid($str, $pos, $end - $pos); Extracts it from the middle EndFunc
×
×
  • Create New...