Solved

Determine if a string value exists within a string

Posted on 2013-11-15
5
361 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
ID: 39651652
if(yourString.Contains("AMEX"))
{

}
0
 
LVL 15

Assisted Solution

by:unknown_routine
unknown_routine earned 75 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 150 total points
ID: 39651677
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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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…

867 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