c# - 更改字符串以将 "A"、 "An"、 "The"移动到 c# 中字符串末尾的最佳方法

标签 c# string substring

我有很多电影(目前有 1000 部,但很容易达到 5000 部)。我想为电影设置“正确”的标题,这意味着将“A”、“An”、“The”移动到标题的末尾(即“The Chronicles of Narnia”变成“Chronicles of Narnia, The”)。

我可以用子字符串做一些 if 语句,但我正在寻找最有效/最快的方法来做到这一点。

建议?

最佳答案

string title = "The Chronicles of Narnia";
string newTitle = Regex.Replace(title, "^(the|a|an) (.*)$", "$2, $1", RegexOptions.IgnoreCase);

Console.WriteLine(newTitle);

关于c# - 更改字符串以将 "A"、 "An"、 "The"移动到 c# 中字符串末尾的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6661280/

相关文章:

c# - TimeZoneInfo.Local 与 TimeZoneInfo.FindSystemTimeZoneById

java - 使用可比较或比较器接口(interface)使用字符串 s1 的顺序对字符串 s2 进行排序

string - 如何在 Haskell 中制作开始/结束索引列表?

sql - 传递给 LEFT 或 SUBSTRING 函数的长度参数无效 ERROR msg

html - 在索引处的字符串中插入字符串(快速)

c# - Mono 中缺少哪些 .NET 元素?

c# - 简单注入(inject)器的工厂设施

c# - 带有 SQL Server 数据库和 Entity Framework 错误的 Windows 应用程序部署

python - 不区分大小写 'in'

string - 检查字符串变量是否为空或空,或充满空格