I am trying to do a function that is a textBox contains 2 dots (.) then the last dot(.) will be deleted, so it wont be possible to write 2 dots(.) in this textbox.

When I write the second dot in this textBox, then also the first is deleted, for example if I write this string:

"0.." -> here I want the last dot to be deleted but the first dot is also deleted. I cant figure out what I am doing wrong:

private void Value2_TextChanged(Object^ sender, TextChangedEventArgs^ e)
        {
            String^ GetValue2 = InputValue2->Text->Trim();
            int DotCount = 0;

            for( int i = 0; i < GetValue2->Length; i++ )
            {
                if( GetValue2->Substring(i, 1) == "." )
                {
                    DotCount = DotCount + 1;
                }
                if( DotCount == 2 )
                {
                    GetValue2 = GetValue2->Replace(GetValue2->Substring(i, 1), "");
                    Value2->Text = GetValue2;
                    Value2->SelectionStart = GetValue2->Length;
                    break;
                }
            }
}

Instead of simply counting the periods (dots) in the first if statement, why don't you store the location of the second one and remove it after the for loop exits? Your TextChanged() event will be firing each time you type anyway...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.