0

I have a string like "Akzo_Nobel_N@46@V@46@".

The original string is "Akzo Nobel N.V."

I need to decode it. I have tried like this

public static string Decode(string query)
{
    string dSData = HttpUtility.UrlDecode(query.ToString());
    return dSData;
}

I am not able to decode this into the original string. Please help me decode it.

Marko
  • 20,385
  • 13
  • 48
  • 64
SRIRAM
  • 1,888
  • 2
  • 17
  • 17

3 Answers3

1
public static String Decode(String query) {
    return query.Replace("_", " ").Replace("@46@", ".");
}

More input would provide a better decoding routine.

sisve
  • 19,501
  • 3
  • 53
  • 95
  • This is based on the assumption that these are the only two replacements OP will have to deal with. +1 though, I'm guessing you knew that, and your code is spot on. –  Sep 06 '12 at 08:33
0

If all you're ever going to deal with is the 'encoded' version of spaces and full stop characters, then just call a string.replace and replace '_' with ' ' and "@46@" with " ". http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx. If it's possible you'll come accross other ascii 'encoding' then you'll need to decode in the right way using the right methods (probably from the same class/library that encoded it).

-1

It looks like the format is:

@xx@ where xx is a decimal number for the ASCII character (so a . is 46) and spaces are replaced by underscores.

Looks like a home-brew URL encoding mechanism but could be wrong.

So what you want is a regular expression that looks for something like @[0-9]{1,3}@ and replace it with the actual character represented by the ascii code.

There may be other straight substitutions other than the _ for spaces, but that's as much as I can tell you.

PhonicUK
  • 13,486
  • 4
  • 43
  • 62
  • How is that in any way relevant? – PhonicUK Sep 06 '12 at 08:49
  • 1
    The string.replace answer will only sort out the _ and @46@, a regular expression is needed to sort out all potential values based on what I have determined the encoding to be. What if they decode another string that has @64@ in it? (which should be an @ character) You'd need a regular expression to find all the combinations. A string.replace on its own is no use for finding complex patterns, but of course you'd not use a regexp.replace for static strings. – PhonicUK Sep 06 '12 at 09:04