Jump to content

How to search a string?


Recommended Posts

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)

Link to comment
Share on other sites

  • 5 months later...

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]
Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

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