Solved

Determine if a string value exists within a string

Posted on 2013-11-15
5
360 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 150 total points
Comment Utility
if(yourString.Contains("AMEX"))
{

}
0
 
LVL 15

Assisted Solution

by:unknown_routine
unknown_routine earned 75 total points
Comment Utility
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 150 total points
Comment Utility
but what if amex is at the beginning of the string... then that would fail.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 75 total points
Comment Utility
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
Comment Utility
All solutions are workable.

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now