System.Xml.XmlComplianceUtil.StripSpaces C# (CSharp) Méthode

StripSpaces() public static méthode

public static StripSpaces ( char value, int index, int &len ) : void
value char
index int
len int
Résultat void
        public static void StripSpaces( char[] value, int index, ref int len ) {
            if ( len <= 0 ) {
               return;
            }

            int startPos = index;
            int endPos = index + len;

            while ( value[startPos] == 0x20 ) {
                startPos++;
                if ( startPos == endPos ) {
                    len = 1;
                    return;
                }
            }

            int offset = startPos - index;
            int i;
            for ( i = startPos; i < endPos; i++ ) {
                char ch;
                if ( ( ch = value[i] ) == 0x20 ) {
                    int j = i + 1;
                    while ( j < endPos && value[j] == 0x20 ) {
                        j++;
                    }
                    if ( j == endPos ) {
                        offset += ( j - i );
                        break;
                    }
                    if ( j > i+1 ) {
                        offset += ( j - i - 1 );
                        i = j - 1;
                    }
                }
                value[i-offset] = ch;
            }
            len -= offset;
        }

Same methods

XmlComplianceUtil::StripSpaces ( string value ) : string

Usage Example

Exemple #1
0
 internal void TrimSpacesInValue()
 {
     if (ValueBuffered)
     {
         XmlComplianceUtil.StripSpaces(chars, valueStartPos, ref valueLength);
     }
     else
     {
         value = XmlComplianceUtil.StripSpaces(value);
     }
 }