System.Globalization.TextElementEnumerator.GetTextElement C# (CSharp) Method

GetTextElement() public method

public GetTextElement ( ) : String
return String
        public String GetTextElement()
        {
            if (index == startIndex) {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted"));
            }
            if (index > strLen) {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumEnded"));                        
            }                
            
            return (str.Substring(index - currTextElementLen, currTextElementLen));
        }
        

Usage Example

Esempio n. 1
0
    public void OnValueChange()
    {
        if (field != null)
        {
            string inStr = field.text;

            if (inStr.Length != 0)
            {
                System.Text.StringBuilder retStr = new System.Text.StringBuilder();
                System.Globalization.TextElementEnumerator tee =
                    System.Globalization.StringInfo.GetTextElementEnumerator(inStr);
                tee.Reset();

                while (tee.MoveNext())
                {
                    // 1文字取得
                    var te = tee.GetTextElement();
                    // 1文字が2つ以上のcharからなる場合は、サロゲートペアと判断
                    if (1 < te.Length)
                    {
                        // 文字列から除去
                    }
                    else
                    {
                        retStr = retStr.Append(te);
                    }
                }
                // InputFieldに返す
                field.text = retStr.ToString();
            }
        }
    }
All Usage Examples Of System.Globalization.TextElementEnumerator::GetTextElement