Solved

Determine if a string value exists within a string

Posted on 2013-11-15
5
365 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 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 86

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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