Sign in to follow this  
Followers 0
lolp1

How to search a string?

6 posts in this topic

Hello, I need to find a way to search for a string inside a string... I can't find the func in help file...

My goal is to do something like this, search for the string inside a string, and if it is found act accordingly.

Example:

If $stringsearch > 1 then

; do what ever.

(Assuming it = 1 if it finds the string)

Share this post


Link to post
Share on other sites



Try function StringInStr.


[right]Software is like sex - it's better when it's free. (Linus Torvalds)[/right]

Share this post


Link to post
Share on other sites

How comes if I use this help file code I get RESULT '10' ? shouldnt the result be 'ring' ?

$result = StringInStr("I am a String", "ring")
MsgBox(0, "Search result:", $result)

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

These are the return values of StringInStr():

Success: Returns the position of the substring.

Failure: Returns 0 if substring not found.

@Error 0 - Normal operation

1 - Occurrence was 0. Occurrence must be a positive or negative integer.

Basically, it's just useful to know if the substring is in the string and where it is.

Share this post


Link to post
Share on other sites

Just do a $str = StringTrimLeft($str, $result) and you'll get ring.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Just do a $str = StringTrimLeft($str, $result) and you'll get ring.

That has nothing to do with searching a string.

When you are searching like this and expecting the same value you entered to be returned that makes no sense, that value is already known.

$result = StringInStr("I am a String", "ring")
MsgBox(0, "Search result:", $result)oÝ÷ Øò¢èî²ÙÞyÖ¢^j{j·!Ê¢Øb±«­¢+Ù%MÑÉ¥¹%¹MÑÈ ÅÕ½Ðí$´MÑÉ¥¹ÅÕ½Ðì°ÅÕ½ÐíÉ¥¹ÅÕ½Ðì¤Q¡¸(í
½)¹%
Edited by weaponx

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