简体   繁体   English

如何检查字符串.net中某个位置的字符

[英]How to check characters at a certain position in a string .net

In my project the customer have a card and a 7 letter particular security code is in it. 在我的项目中,客户有一张卡,里面有一个7字母的特定安全码。 I want to ask 3 letters from that security code by position. 我想按位置询问该安全代码中的3个字母。

eg. card security code is  **57GHY58**

I want to ask what is the Character at 2,4 and 7 position in your security code ? 我想问一下您的安全代码在2,4和7位的字符是什么

answer is  **7H8**

How to generate that question with random postion and how to check it ? 如何生成带有随机位置的问题并进行检查

private static int[] GetThreeRandomNumbers()
{
    List<int> list = new List<int>();
    Random r = new Random();
    while (list.Count < 3)
    {
        int num = r.Next(1, 7);
        if (!list.Contains(num))
        {
            list.Add(num);
        }
    }
    list.Sort();
    return list.ToArray();
}

You have a string with indices 0-6. 您有一个索引为0-6的字符串。 You need to pick 3 indices from that range randomly. 您需要从该范围中随机选择3个索引。 The Random class will help you with this, have a look at its method Random.Next(int, int) , it will return you a random number from the specified range. Random类将帮助您解决此问题,请查看其方法Random.Next(int, int) ,它将为您返回指定范围内的随机数。 Then the only other thing you have to do is skip the indices you have already used. 然后,您要做的唯一另一件事就是跳过已经使用的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何格式化字符串以删除某些字符(.NET Razor)? - How can I format a string to remove certain characters (.NET Razor)? 将字符串设置到某个位置 - set string to a certain position 检查字符串中是否包含无效字符 - check string for invalid characters 如何替换这些“ / \\\\ []:| | &lt;&gt; + =; ,? *” asp.net中带有空字符串的字符串中的字符 - How to Replace any of these “/ \\ [ ] : | < > + = ; , ? *” Characters in a string with empty string in asp.net 如何检查字符串是否包含长度超过50个字符的单词? - How to check if a string contains a word longer than 50 characters? 在某些字符前后修剪字符串 - Trim a string before and after certain characters 如何在asp.net中检查一天是否是特定日期c#.net - How to check if a day is a certain date in asp.net c#.net 如何在C#中检查是否可以使用另一个字符串的字符获取一个字符串? - How to check if a string can be obtained using another string's characters in c#? 我如何用正则表达式检查字符串,该字符串包含12个字符并包含0-9a-f? - How I can check a string with Regular expressions about the string has 12 characters and contains 0-9a-f? 检查字符串什么都没有,然后在1行中确定值? - check string for nothing and then for certain value in 1 line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM