Sign in to follow this  
Followers 0
Syed23

Finding a string

6 posts in this topic

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]

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!"

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
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]

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