Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Help manipulate a string

Posted on 2012-03-22
3
Medium Priority
?
295 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
[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
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
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, …

647 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