?
Solved

Help manipulate a string

Posted on 2012-03-22
3
Medium Priority
?
298 Views
Last Modified: 2012-03-26
This is a question related to :  

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_27644050.html


the problem is if the string looks up first the second part of the string in the list

sbKeys will be inverted

for example:

lets say the list is :

Per1, Period 1
TY, This Year
LY, Last Year
Q1, This is Q1
Q2, This is Q2


and string is:   "This Year Period 1'

sbKeys will be:   "Per1_TY"

but the real result would need to be:  "TY_Per1"
like if it must be from left to right..

how could we modify the code ?
0
Comment
Question by:PhilippeRenaud
3 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37754116
is this c# or vb
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 37754255
vb
0
 
LVL 6

Accepted Solution

by:
effes earned 2000 total points
ID: 37754279
If the string you examine always contains just two parts replace
dictionary
        .Keys
        .ToList()
        .ForEach(key =>
        {
            if (stringToMatch.ToLower().Contains(dictionary[key].ToLower()))
            {
                if (sbKeys.Length > 0)
                    sbKeys.Append(",");

                sbKeys.Append(key);
            }
        });

Open in new window

with
dictionary
        .Keys
        .ToList()
        .ForEach(key =>
        {
            if (stringToMatch.ToLower().StartsWith(dictionary[key].ToLower()))
            {
                sbKeys.Append(key);
            }
        });

dictionary
        .Keys
        .ToList()
        .ForEach(key =>
        {
            if (stringToMatch.ToLower().EndsWith(dictionary[key].ToLower()))
            {
                sbKeys.Append(",");
                sbKeys.Append(key);
            }
        });

Open in new window

(Sorry that it is C#, but it is based on the code from the old question.)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

831 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