c# - 如何在 C# 中将字符串拆分为单词

标签 c#

如何将以下字符串拆分为单词

字符串exp=price+10*discount-30

进入

string[]words={'价格',折扣'}

最佳答案

您可以使用正则表达式匹配单词,然后得到结果。

示例:

        // This is the input string.
        string input = "price+10*discount-30";

        var matches = Regex.Matches(input, @"([a-z]+)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
        foreach (var match in matches)
        {
            Console.WriteLine(match);
        }
        Console.ReadLine();

关于c# - 如何在 C# 中将字符串拆分为单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13821252/

相关文章:

c# - 程序集未加载 c#

c# - 在 .netcore 中使用同一个 nuget 包的多个版本

c# - 缺少引用

c# - Blazor 组件双向数据绑定(bind)

c# - 如何拆分一个长字符串,使其与给定的矩形匹配?

c# - TreeView 项目更改事件

c# - 将表达式<Action<T>> 转换为表达式<Func<T>>

c# - 使用获取 "Object reference not set to an instance of an object"的任务

c# - 与我托管的 Windows 服务的安装程序一起,是否可以在发生错误时设置恢复选项?

javascript - ASPDotNetStorefront 登录后无法加载资源文件