System.Xml.XmlConverter.StripWhitespace C# (CSharp) Méthode

StripWhitespace() static public méthode

static public StripWhitespace ( string s ) : string
s string
Résultat string
        static public string StripWhitespace(string s)
        {
            int count = s.Length;
            for (int i = 0; i < s.Length; i++)
            {
                if (IsWhitespace(s[i]))
                {
                    count--;
                }
            }
            if (count == s.Length)
                return s;
            char[] chars = new char[count];
            count = 0;
            for (int i = 0; i < s.Length; i++)
            {
                char ch = s[i];
                if (!IsWhitespace(ch))
                {
                    chars[count++] = ch;
                }
            }
            return new string(chars);
        }

Usage Example

Exemple #1
0
 public byte[] ToByteArray()
 {
     if (_type == ValueHandleType.Base64)
     {
         byte[] buffer = new byte[_length];
         GetBase64(buffer, 0, _length);
         return(buffer);
     }
     if (_type == ValueHandleType.UTF8 && (_length % 4) == 0)
     {
         try
         {
             int expectedLength = _length / 4 * 3;
             if (_length > 0)
             {
                 if (_bufferReader.Buffer[_offset + _length - 1] == '=')
                 {
                     expectedLength--;
                     if (_bufferReader.Buffer[_offset + _length - 2] == '=')
                     {
                         expectedLength--;
                     }
                 }
             }
             byte[] buffer       = new byte[expectedLength];
             int    actualLength = Base64Encoding.GetBytes(_bufferReader.Buffer, _offset, _length, buffer, 0);
             if (actualLength != buffer.Length)
             {
                 byte[] newBuffer = new byte[actualLength];
                 Buffer.BlockCopy(buffer, 0, newBuffer, 0, actualLength);
                 buffer = newBuffer;
             }
             return(buffer);
         }
         catch (FormatException)
         {
             // Something unhappy with the characters, fall back to the hard way
         }
     }
     try
     {
         return(Base64Encoding.GetBytes(XmlConverter.StripWhitespace(GetString())));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(exception.Message, exception.InnerException));
     }
 }
All Usage Examples Of System.Xml.XmlConverter::StripWhitespace