?
Solved

Determine if a string value exists within a string

Posted on 2013-11-15
5
Medium Priority
?
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 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