How to find a comma inside a TextBox

1

I have a Text Box in which it can only contain a comma, so I thought about having the program detect when the user uses the comma if there already exists one in that particular Text Box.

Here is an example of the code I want to get:

if(*Verificar se já existe uma vírgula no textBox1) { //não fazer nada } else { this->textBox1->Text += ","; }

    
asked by anonymous 03.08.2018 / 14:55

2 answers

1

I ended up using marshal, here is the resolution:

char* Valor = (char*)(void*)Marshal::StringToHGlobalAnsi(textBox1->Text);
ContadorDeVirgulas = strchr(Valor, ',');
if(ContadorDeVirgulas > 0) {
}
else {
    this->textBox1->Text += ",";
}
    
03.08.2018 / 18:54
0

I do not know if this-> textBox1-> Text is a std :: string but if you just walk around it looking for commas:

int contadorDeVirgulas = 0;
for(int i = 0; i < str.size(); ++i) 
{
    if (str[i] == ",")
        contadorDeVirgulas++;
}

Then just ask

if(contadorDeVirgulas > 0) 
{
    //não fazer nada
}
else 
{
    this->textBox1->Text += ",";
}

If you need to check in several places you can use this for inside a function or lambda (depending on the case).

    
03.08.2018 / 15:36