Jump to content

Search a word in a text


Recommended Posts

Okay here's my idea

I want to read a specific line of a text document, search it for a specific word and display that word

as a label in my GUI

Now my problem is

The word can differ, it can be 6 different words like: hello,no,yes,maybe,sir,yellow

i did some research and found this

StringRegExp and StringInStr - but they just give me numbers and i dont really know how to use them

The help file doesnt help me at all because i dont understand it :)

well thx for your answers :)

Link to comment
Share on other sites

$sValue = "Hello, this is a test."
If StringRegExp($sValue, "(?i:hello|no|yes|maybe|sir|yellow)", 0) Then DoWhateverYouWant()
well - when i did this i got 1 on success - 0 on failure

Now that CAN help me - but im looking for an easier way since i would have to write 200 lines of code just for one thing using

StringRegExp -because there is actually 200 posibilities -

now is there a way to search a string - lets say 'hello<"name = 77618">' - for the value after 'hello<"name = ... and then save it to

another string ? if so could you please tell me :)

thx for your answers

Link to comment
Share on other sites

Strininstr()

OR

stringtrimleft()  Stringtrimright()

OR

stringreplace()

whatever you need please CHECK THE HELP FILE its your best friend in autoit

Link to comment
Share on other sites

Strininstr()

OR

stringtrimleft()  Stringtrimright()

OR

stringreplace()

whatever you need please CHECK THE HELP FILE its your best friend in autoit

but all those expressions do is check if that word is in there - is there an expression that can read a specific word at a specific place

and then diplay it onto the gui ?

if not ill have to go with the other expressions - but 200 lines of code x.x

well thx for your answers

Link to comment
Share on other sites

well - when i did this i got 1 on success - 0 on failure

Now that CAN help me - but im looking for an easier way since i would have to write 200 lines of code just for one thing using

StringRegExp -because there is actually 200 posibilities -

now is there a way to search a string - lets say 'hello<"name = 77618">' - for the value after 'hello<"name = ... and then save it to

another string ? if so could you please tell me :)

thx for your answers

This may give you some ideas.

#include <Array.au3>

; From post 
; http://www.autoitscript.com/forum/index.php?s=&showtopic=89105&view=findpost&p=640323
; - lets say 'hello<"name = 77618' - for the value after 'hello<"name = ... and 
; then save it to another string ?

$sString = 'Extra text here hello<' & '"' & 'name = 77618' & '"' & '> and here' 

; That which is found between the brackets, (), is returned to the array.
; This case: \d is any digit. * means repeat the previous character 0 or more times.
; So this will search the $sString for the text in the regular expression, and will
; return all occurances of the digits, if any, that appear after [hello<"name = ] and 
; before [">]
$array = StringRegExp($sString, 'hello<' & '"' & 'name = (\d*)' & '"' & '>' , 3) 

_ArrayDisplay($array)
$sAnotherString = _ArrayToString($array)
MsgBox(0,"A String",$sAnotherString)


#cs
; Easier to search whole of file instead of one line at a time.Will return an array 
; of all matches.
$sFile = "FullPath\and\FileName.txt" ; Full path if not in same script directory.
$sRegExp = 'hello<' & '"' & 'name = (\d*)' & '"' & '>' 
StringRegExp(FileRead($sFile), $sRegExp , 3)
#ce
Link to comment
Share on other sites

This may give you some ideas.

#include <Array.au3>

; From post 
; http://www.autoitscript.com/forum/index.php?s=&showtopic=89105&view=findpost&p=640323
; - lets say 'hello<"name = 77618' - for the value after 'hello<"name = ... and 
; then save it to another string ?

$sString = 'Extra text here hello<' & '"' & 'name = 77618' & '"' & '> and here' 

; That which is found between the brackets, (), is returned to the array.
; This case: \d is any digit. * means repeat the previous character 0 or more times.
; So this will search the $sString for the text in the regular expression, and will
; return all occurances of the digits, if any, that appear after [hello<"name = ] and 
; before [">]
$array = StringRegExp($sString, 'hello<' & '"' & 'name = (\d*)' & '"' & '>' , 3) 

_ArrayDisplay($array)
$sAnotherString = _ArrayToString($array)
MsgBox(0,"A String",$sAnotherString)


#cs
; Easier to search whole of file instead of one line at a time.Will return an array 
; of all matches.
$sFile = "FullPath\and\FileName.txt" ; Full path if not in same script directory.
$sRegExp = 'hello<' & '"' & 'name = (\d*)' & '"' & '>' 
StringRegExp(FileRead($sFile), $sRegExp , 3)
#ce

i still dont get it .... ive been trying to understand it for 2 hours , reading the helfile, searching the forum, i just dont get it !

could you maybe do another example using the code i'll be using

so

$a = <option name="HP_LOW" value="85" />

[ find the value after 'value="... ]

Thx for your answers

EDIT::

with the _StringBetween

heres the code im trying to use

$a = '<option name="HP_LOW" value="85" />'
$string_between = _StringBetween($a,'value="','" />')
MsgBox(0,"",$string_between)

but it doesn't work - what am i doing wrong ?

Edited by sroprogger
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...