小编Sed*_*dax的帖子

C#从字符串获取字符的位置

我的代码是这样的:

 string dex = "ABCD1234";
 string ch = "C";
 string ch1, ch2;
    if (dex.Contains(ch))
    {
       string n = Convert.ToChar(dex);
       MessageBox.Show(ch + "  is on " + n + " place and is between " + ch1 + " and " + ch2);
    }
Run Code Online (Sandbox Code Playgroud)

我想将字符串转换为数组,但我做不到,也无法检索“ ch”字符串的位置及其之间的位置。

输出应为:

MessageBox.Show("C is on 3rd place and is between B and D");
Run Code Online (Sandbox Code Playgroud)

c# string position char

-1
推荐指数
1
解决办法
6925
查看次数

标签 统计

c# ×1

char ×1

position ×1

string ×1