Click here to Skip to main content
15,885,080 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
SO i want to make a program that can tell the amount of numbers and their locations eg int 4531 it should say 4 numbers And that 1st is 4 second is 5 third is 3 and forth is 1

What I have tried:

int i = textBox3.Text.Count();
            textBox3.Text = i.ToString();
Posted
Updated 11-Sep-18 6:34am
Comments
Patrice T 11-Sep-18 12:00pm    
"SO i want to make a program"
Ok I allow you, you can get started.
Mike Hankey 11-Sep-18 12:24pm    
A simple way would be to convert to character array "ToCharArray() " and just interate though the chars.
see here
OriginalGriff 11-Sep-18 12:36pm    
You don't need to convert it: indexing works with strings, and so does foreach.

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

But ... I'll give you a few hints:
1) A string is also an array (or it can be treated as such) - so you can access each character singly either buy using indexing myString[i] or a foreach loop.
2) You can check for all digits in a string by using TryParse:
C#
int value;
if (int.TryParse(myString, out value))
   {
   // It's a number!
   ...
   }

3) If the string is all digits, the Length of the string is the number of digits.
Put those together, and you're pretty much there...
Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900