?
Solved

Determine if a string value exists within a string

Posted on 2013-11-15
5
Medium Priority
?
368 Views
Last Modified: 2013-11-15
I have the following string:

"C:\Develop\Apps\StockPro\Data\AMEX.txt";

How do I find out if "AMEX" is a substring within the larger string?

blnExists is true if "AMEX" is a substring within "C:\Develop\Apps\StockPro\Data\AMEX.txt";

Thanks
0
Comment
Question by:Dovberman
5 Comments
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 600 total points
ID: 39651652
if(yourString.Contains("AMEX"))
{

}
0
 
LVL 15

Assisted Solution

by:unknown_routine
unknown_routine earned 300 total points
ID: 39651657
string Mystring=@"C:\Develop\Apps\StockPro\Data\AMEX.txt";

if(Mystring.IndexOf("AMEX")>0)

{

bool blnExists=true;
}
0
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 600 total points
ID: 39651677
but what if amex is at the beginning of the string... then that would fail.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 300 total points
ID: 39651820
Hard to tell what you're doing in the actual app.

This might be useful for you:
            string file = @"C:\Develop\Apps\StockPro\Data\AMEX.txt";
            string name = System.IO.Path.GetFileNameWithoutExtension(file);
            if (name.ToUpper() == "AMEX")
            {
                
            }
            else
            {

            }

Open in new window

0
 

Author Closing Comment

by:Dovberman
ID: 39652144
All solutions are workable.

if(Mystring.IndexOf("AMEX")>=0)
Works if "AMEX" starts at position 0.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question