Jump to content

Finding a string


Syed23
 Share

Recommended Posts

Hi Friends,

I need your help to find solution. I have a string in my text file like this "Name=Syed,Age=23,Sex=Male,Interest=Tool creation". so all i wanted is that i should check whether the line have the "string - male" on it. Can some one help me on this?

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Hi Friends,

I need your help to find solution. I have a string in my text file like this "Name=Syed,Age=23,Sex=Male,Interest=Tool creation". so all i wanted is that i should check whether the line have the "string - male" on it. Can some one help me on this?

If you have more than one line in your text file I would do something like:

#include <file.au3>

_FileReadToArray("C:\temp\test.txt", $aResult)
For $iIndex = 1 To $aResult[0]
    If StringInStr($aResult[$iIndex], "Sex=Male") Then
        ; Do whatever you want for every male in your file
    EndIf
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Easier yet, avoid the array

$sStr = FileRead("C:\temp\test.txt")
If StringInStr($sStr, "Sex=Male") Then
     ; Do whatever you want for every male in your file
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

If you have more than one line in your text file I would do something like:

#include <file.au3>

_FileReadToArray("C:\temp\test.txt", $aResult)
For $iIndex = 1 To $aResult[0]
    If StringInStr($aResult[$iIndex], "Sex=Male") Then
        ; Do whatever you want for every male in your file
    EndIf
Next

Thanks a lot!! :graduated: This is what i wanted exactly... you are amazing. MAy i know your name? I am Syed.

Could you please explain me how it works.. because i wanted to do if some thing needed to work with string in futurer. Will you please??

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Thanks a lot!! :graduated: This is what i wanted exactly... you are amazing. MAy i know your name? I am Syed.

Could you please explain me how it works.. because i wanted to do if some thing needed to work with string in futurer. Will you please??

It reads the file into an array, every line goes into one array element. Then it works through the array and for every line it encounters, it checks whether the line contains "Sex=Male". If the line contains that string, it does the "whatever you want" line.

About your question "because i wanted to do if some thing needed to work with string in futurer."... I'm not sure how to answer that... :(

Btw, I'm SadBunny... :D

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

It reads the file into an array, every line goes into one array element. Then it works through the array and for every line it encounters, it checks whether the line contains "Sex=Male". If the line contains that string, it does the "whatever you want" line.

About your question "because i wanted to do if some thing needed to work with string in futurer."... I'm not sure how to answer that... :graduated:

Btw, I'm SadBunny... :D

Thanks a lot :(

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

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...