class MyArray
{
static void Main(string[] args)
{
String str = "heros never die";
char[] newss=Str(str);
for (int i = 0; i < newss.Length; i++)
{
Console.Write(newss[i]);
}
}
public static char[] Str(string str)
{
char[] oldstr = str.ToCharArray();
char[] newstr = new char[100];
for (int i = 0; i < oldstr.Length; i++)
{
newstr[i] = oldstr[i];
}
int black = 0;
for (int j = 0; j < newstr.Length; j++)
{
if (newstr[j] == ' ')
black++;
}
int front = oldstr.Length - 1;
int back = oldstr.Length + 2 * black - 1;
while (front>=0&&back>=0)
{
if (newstr[front] != ' ')
{
newstr[back--] = newstr[front];
}
else
{
newstr[back--] = '0';
newstr[back--] = '2';
newstr[back--] = '%';
}
front--;
}return newstr;
}
}((c#))替换空格
最新推荐文章于 2023-11-20 18:48:23 发布
本文介绍了一个使用C#实现的字符数组操作示例,包括字符串到字符数组的转换及特殊字符处理过程。通过一个具体的例子展示了如何遍历字符串,并进行字符级别的操作。
760

被折叠的 条评论
为什么被折叠?



