如何检查数字中数字的位置 [英] How do I check the location of a digit in a number

查看:85
本文介绍了如何检查数字中数字的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想制作一个程序,可以告诉数字和它们的位置数量,例如int 4531它应该说4个数字而1st表示4秒是5个三分之三是3个就是1



我的尝试:



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();

推荐答案

我们不做你的作业:它设置为原因。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



但是......我会给你一个一些提示:

1)一个字符串也是一个数组(或者它可以被视为这样) - 所以你可以单独访问每个字符要么使用索引购买 myString [i] foreach 循环。

2)您可以使用TryParse检查字符串中的所有数字:

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:
int value;
if (int.TryParse(myString, out value))
   {
   // It's a number!
   ...
   }



3)如果字符串是全数字,字符串的长度是数字。

把它们放在一起,你就在那里......

亲自尝试,你可能会发现它并不像你想象的那么难!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!


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!


这篇关于如何检查数字中数字的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆