[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to find a string between two begin and end strings in C#

Posted on 2011-04-26
7
Medium Priority
?
393 Views
Last Modified: 2012-05-11
Hi,

how to find a string between two begin and end strings in C#

Ex:  
string begin ="G1G", end ="G4L";
string value ="G2L";

IF value >= begin && value <= end  // TODO  Error
{
   return true;
}

thank for your help
0
Comment
Question by:raymmich1981
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35467857
Hi, This is what you want?

            string begin = "G1G", end = "G4L";
            string value = "G2L";
            if (value.StartsWith(begin) & value.EndsWith(end))
                return true;

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35467984
Can you give more details?  Will it always be one letter, followed by one digit, followed by one letter?...or can there be a longer number in-between the letters?...or possibly any number of letters, followed by digits, followed by letters?
0
 

Author Comment

by:raymmich1981
ID: 35468235
Yes it always be one letter, followed by one digit, followed by one letter

In Vb .Net
this work  but not in C#

IF value >= begin  andalso value <= end  
{
   return true;
}
0
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!

 
LVL 12

Expert Comment

by:FarWest
ID: 35468375
Your Question can be miss-understood, I think you need a string range check
using string.compare
check this url
http://msdn.microsoft.com/en-us/library/zkcaxw5y.aspx#Y1499
please note the negitive results for less
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 35468646
Right...you could wrap two String.Compare() calls into a function:
private void button1_Click(object sender, EventArgs e)
        {
            string beginValue = "G1G";
            string endValue = "G4L";
            dynamic curValue = "G2L";

            if (Between(beginValue, curValue, endValue))
            {
                Console.WriteLine("Between");
            }
            else
            {
                Console.WriteLine("Not Between");
            }
        }

        private bool Between(string beginValue, string curValue, string endValue)
        {
            return (curValue.CompareTo(beginValue) >= 0) && (curValue.CompareTo(endValue) <= 0);
        }

Open in new window

0
 

Author Closing Comment

by:raymmich1981
ID: 35469088
Thank you it's want i need !!
0
 
LVL 12

Expert Comment

by:FarWest
ID: 35469120
at least you colud mark my answer as assested
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

872 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