Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to get a number of a string, and separate the string and the number, and then, do a loop and call a method the number of times the string says. The string has to have this structure: "ABJ3" (Only one number accepted and 3 characters before it)

This is my code, but it repeat hundred of times, I don't know why

            int veces = 0;
            for (int i = 0; i < m.Length; i++)
            {
                if (Char.IsDigit(m[i]))
                    veces = Convert.ToInt32(m[i]);
            }

            if (m.Length == 4)
            {
                for (int i = 0; i <= veces; i++)
                {
                    m = m.Substring(0, 3);
                    operaciones(m, u, t);
                    Thread.Sleep(100);
                }
            }
            operaciones(m,u,t);
            if (u.Length >= 14)
            {
                u = u.Substring(0, 15);
            }

Some help please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
235 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to convert your m[i] ToString() right now you are sending the char value to Convert.ToInt32 and that is a much higher value (9 = 57 for example)

char t = '9';

int te = Convert.ToInt32(t.ToString());

Console.WriteLine(te);

This gives us a result of 9 but

char t = '9';

int te = Convert.ToInt32(t);

Console.WriteLine(te);

Gives us a result of 57

So you need to change

veces = Convert.ToInt32(m[i]);

to

veces = Convert.ToInt32(m[i].ToString());

Hope it helped.

Best regards //KH.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...