Solved

Help manipulate a string

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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