Je suis dans un processus de conception de calculatrice relationnelle.Problème avec les chaînes
Si un utilisateur a fourni une chaîne comme -3,33 + 44 * 456/2.2-3 + 4 ....
Je veux stocker dans le tableau de chaîne comme
-3,33
+44
*
/
2,2
-3
+4
...... (qui est *, /, + ve valeur, la valeur -ve séparément et dans un ordre en série dans un tableau de chaînes)
Voici le code que j'ai écrit:
string a = "-3.33+44*456/2.2-3";
string[] ip = new string[25];
int k = 0;
for (int i = 0; i < a.Length; i++)
{
if (a.Substring(i, 1) == "+" || a.Substring(i, 1) == "-" || a.Substring(i, 1) == "*" || a.Substring(i, 1) == "/" || a.Substring(i, 1) == "^")
{
for (int j = i + 1; j < a.Length; j++)
{
if (a.Substring(j, 1) == "+" || a.Substring(j, 1) == "-" || a.Substring(j, 1) == "*" || a.Substring(j, 1) == "/" || a.Substring(j, 1) == "^")
{
if (a.Substring(i, 1) == "+" || a.Substring(i, 1) == "-")
{
ip[k] = a.Substring(i, j-i);
k++;
}
else
{
ip[k] = a.Substring(i, 1);
k++;
ip[k] = a.Substring(i + 1, (j -i)-1);
k++;
}
i = j;
break;
}
}
}
}
Mais sa ne fonctionne pas correctement: Son stockage d'un seul élément dans le tableau.
Depuis deux jours, je freine ma tête. S'il vous plaît aidez-moi. Merci.
Comment utiliser ce code? Comment pouvons-nous l'intégrer dans des formulaires Windows? – Gokul
Un peu trop haut ne pensez-vous pas? – ChaosPandion