Solved

Help manipulate a string

Posted on 2012-03-22
3
283 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
Comment Utility
is this c# or vb
0
 
LVL 1

Author Comment

by:PhilippeRenaud
Comment Utility
vb
0
 
LVL 6

Accepted Solution

by:
effes earned 500 total points
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

10 Experts available now in Live!

Get 1:1 Help Now