使用while循环从字符串的开头删除空格

发布于 2025-02-10 23:29:16 字数 321 浏览 1 评论 0原文

我做了什么。当我在纸上浏览这种算法时,这是有道理的...我在哪里错了?我无法使用Trim方法,因为该任务是使用一个while循环 我知道我有点愚蠢,因为我无法弄清楚这项最简单的任务,但是请您提前感谢任何会解释这件事的人!

public static string RemoveStartSpaces(string text)
{
    int i = 0;
    while (char.IsWhiteSpace(text[i]))
    {
        i++;
        text.Substring(i);
    }
    return text;
}

i did something. when i go through this algorithm on a paper, it makes sense... where am i wrong? i can't use trim method because the task is to use a while loop
i know i'm kinda stupid 'cause i can't figure out this simplest task, but thank you in advance to anyone who'll explain this thing!

public static string RemoveStartSpaces(string text)
{
    int i = 0;
    while (char.IsWhiteSpace(text[i]))
    {
        i++;
        text.Substring(i);
    }
    return text;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文