System.Uri.UnescapeDataString C# (CSharp) Method

UnescapeDataString() public static method

public static UnescapeDataString ( string stringToUnescape ) : string
stringToUnescape string
return string
        public static string UnescapeDataString(string stringToUnescape)
        {
            if ((object)stringToUnescape == null)
                throw new ArgumentNullException(nameof(stringToUnescape));

            if (stringToUnescape.Length == 0)
                return string.Empty;

            unsafe
            {
                fixed (char* pStr = stringToUnescape)
                {
                    int position;
                    for (position = 0; position < stringToUnescape.Length; ++position)
                        if (pStr[position] == '%')
                            break;

                    if (position == stringToUnescape.Length)
                        return stringToUnescape;

                    UnescapeMode unescapeMode = UnescapeMode.Unescape | UnescapeMode.UnescapeAll;
                    position = 0;
                    char[] dest = new char[stringToUnescape.Length];
                    dest = UriHelper.UnescapeString(stringToUnescape, 0, stringToUnescape.Length, dest, ref position,
                        c_DummyChar, c_DummyChar, c_DummyChar, unescapeMode, null, false);
                    return new string(dest, 0, position);
                }
            }
        }

Usage Example

Example #1
0
        private string GetUnescapedAbsolutePath(Uri uri)
        {
            string absolutePath = Uri.UnescapeDataString(uri.AbsolutePath);

            return(absolutePath.EndsWith("/", StringComparison.Ordinal) ? absolutePath.Substring(0, absolutePath.Length - 1) : absolutePath);
        }
All Usage Examples Of System.Uri::UnescapeDataString