gpt4 book ai didi

c# - 将字符串转换为带有字母的数组

转载 作者:太空宇宙 更新时间:2023-11-03 17:49:10 28 4
gpt4 key购买 nike

基本上我想做的就是拿一个字符串

string test = "hello";


然后将其转换为数组:

string[] testing = { "h", "he", "hel", "hell", "hello" };


这可能吗?

最佳答案

尝试使用Linq:

  string test = "hello";

string[] testing = Enumerable
.Range(1, test.Length)
.Select(length => test.Substring(0, length))
.ToArray();


测试:

  // h, he, hel, hell, hello
Console.Write(string.Join(", ", testing));

关于c# - 将字符串转换为带有字母的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40226690/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com