Solved

Help manipulate a string

Posted on 2012-03-22
3
291 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 500 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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