【发布时间】:2022-01-15 15:18:58
【问题描述】:
当您的字符串在数组中编入索引时,有人可以帮我通过字符串插值打印出一个字符串而不是一个字符吗?打印在 if 语句 - {text[3]} 等
static void Main(string[] args)
{
string textDoc = "The first world war occurred in the early 20th century, many countries around the world were originally agnostic to the early battles. An obvious reason why is because there are many countries in the world that do not have relations to nation states that were fighting in the early battles.";
string[] textSplit = textDoc.Split(" ");
foreach (string text in textSplit) {
if(text.StartsWith("a")) {
Console.WriteLine($"Roses {text[2]} red, scarlets {text[2]} blue, this poem doesn't have {text[3]} ending, so embrace the unknown because it is {text[1]}.");
break;
}
}
{text[3]} 打印出字符 - "a",而不是字符串 - "are"。
谢谢。
【问题讨论】:
标签: c# arrays string char string-interpolation