Re: parse string CN= OU= O=

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Alhambra Eidos Development" <AlhambraEidosDevelopment@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:7E3747A8-E083-480C-9C32-8D0BE5822C9A@xxxxxxxxxxxxxxxx

Thanks, mister.

LOL! You're welcome, mate.


The problem is

CN="MAORI RAMOS, PEPE (AUTENTICACIÓN)"

Apologies, I missed that...

Below is some code that will fix that, but it's a bit of a hack - hopefully, someone else will provide a better alternative:

string strRaw = "C=ES, SERIALNUMBER=123456789R, SN=MAORI, G=PEPE, CN=\"MAORI RAMOS, PEPE (AUTENTICACIÓN)\"";
Regex objRegex = new Regex("\"((.|\n)*?)\"", RegexOptions.IgnoreCase);
foreach (Match objMatch in objRegex.Matches(strRaw))
{
string strTextInQuotes = objMatch.ToString().Trim('\"').Replace(",", "¬");
strRaw = strRaw.Replace(objMatch.ToString(), strTextInQuotes);
}
List<string> lstRaw = new List<string>(strRaw.Split(','));
Dictionary<string, string> dicRaw = new Dictionary<string, string>();
foreach (string strElement in lstRaw)
{
dicRaw.Add(strElement.Split('=')[0].Trim(), strElement.Split('=')[1].Trim().Replace("¬", ","));
}


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

.



Relevant Pages

  • RE: Performance Issue with ForEach loop
    ... Fix what, exactly? ... has anything to do with the performance of foreach itself. ... > Structures upper division or graduate courses, ... > efficient implemantation of LIST (e.g. the one outlined in Aho, Hopcroft, ...
    (microsoft.public.dotnet.framework.performance)
  • Re: algorithm to compare 3 array elements
    ... There are several syntax mistakes. ... I was trying to learn the forEach from the Mozilla site and ... seemed like the for loop was easier to compare the index. ... I did try to fix the syntax error above with this line and it didn't ...
    (comp.lang.javascript)
  • Re: parse string CN= OU= O=
    ... foreach (Match objMatch in objRegex.Matches(strRaw)) ... It will put all key/value pairs in a match. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: fix a per script
    ... Please help me to fix it. ... for $rec ... foreach $val ) ...
    (comp.lang.perl.misc)
  • Re: Invalid Argument supplied for foreach()
    ... My question is how would you fix this if there are NO results, ... "Sorry we are unable to process your search request or we are unable ... You $products array is empty. ... That way you will avoid the foreach error occurring. ...
    (comp.lang.php)