Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 992443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:16:07+00:00 2026-05-16T06:16:07+00:00

I’m still trying to understand KeyValuePairs but I believe this idea should work. In

  • 0

I’m still trying to understand KeyValuePairs but I believe this idea should work. In my code below it searchs through a large string and extracts 2 substrings. One substring (keep in mind the value between the quotes varies) is something like Identity="EDN\username" another substring is something like FrameworkSiteID="Desoto" So I was thinking about combining these strings together before I added them to the List but here is my problem.. The login string below is a Unique field of strings that I need to use in a SQL statement to select records in SQLServer and the framew strings are strings I need lined up with the login strings (and all the columns and rows of data coming from SQLServer) when I output this to a text file. Should I make the login strings KEYS and the framew strings VALUES? If so how do I do that?? Hope that makes sense. I can further explain if needs be

Regex reg = new Regex("Identity=\"[^\"]*\"");
Regex reg1 = new Regex("FrameworkSiteID=\"[^\"]*\"");

foreach (FileInfo file in Files)
{
    string line = "";
    using (StreamReader sr = new StreamReader(file.FullName))
    {
        while (!String.IsNullOrEmpty(line = sr.ReadLine()))
        {
            if (line.ToUpper().Contains("IDENTITY="))
            {
                string login = reg.Match(line).Groups[0].Value;
                string framew = reg1.Match(line).Groups[0].Value; //added
                IdentityLines.Add(new KeyValuePair<string, string>(file.Name, login + " " + framew));
                    //This is probably not what I need
            }


            else
            {
                IdentityLines.Add(new KeyValuePair<string, string>(file.Name, "NO LOGIN"));
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:16:08+00:00Added an answer on May 16, 2026 at 6:16 am

    I’m note clear what the purpose of this is. You don’t seem to be using the KeyValuePairs as pairs of a Key and a Value. Are you using them as a general pair class? It’s a reasonable use (I do this myself), but I’m not sure what help you are seeking.

    The intended purpose of KeyValuePair is as a helper-class in the implementation of Dictionaries. This would be useful if you are going to look up values based on having a key, though it doesn’t seem from your explanation that you are.

    Why are you using the filename as the key? Does it matter?

    I also don’t see why you are loading all of this stuff into a list. Why not just yield them out and use them as they are found?

    foreach (FileInfo file in Files)
    {
        using (StreamReader sr = new StreamReader(file.FullName))
        {
            for(string line = sr.ReadLine(); !string.IsNullOrEmpty(line); line = sr.ReadLine())
            {
                if(line.IndexOf("IDENTITY=", StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    string login = reg.Match(line).Groups[0].Value;
                    string framew = reg1.Match(line).Groups[0].Value; //added
                    yield return new KeyValuePair<string, string>(login, framew));
                }
            }
        }
    }
    

    On the other hand, if you do want to use them as key-d values:

    Dictionary<string, string> logins = new Dictionary<string, string>();
    foreach (FileInfo file in Files)
    {
        using (StreamReader sr = new StreamReader(file.FullName))
        {
            for(string line = sr.ReadLine(); !string.IsNullOrEmpty(line); line = sr.ReadLine())
            {
                if(line.IndexOf("IDENTITY=", StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    string login = reg.Match(line).Groups[0].Value;
                    string framew = reg1.Match(line).Groups[0].Value; //added
                    logins.Add(login, framew));
                }
            }
        }
    }
    

    Now logins[login] returns the related framew. If you want this to be case-insensitive then use new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) or new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase) as appropriate.

    Finally, are you sure there will be no blank likes until the end of the file? If there could be you should use line != null rather than !string.IsNullOrEmpty() to avoid stopping your file read prematurely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I am trying to understand how to use SyndicationItem to display feed which is
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.