Split a string by another string in C#(在 C# 中用另一个字符串拆分一个字符串)
问题描述
我一直在使用 Split()
方法来拆分字符串,但这似乎只在您按字符拆分字符串时才有效.有没有办法分割一个 string
,另一个字符串是按参数分割的?
I've been using the Split()
method to split strings, but this only appears to work if you are splitting a string by a character. Is there a way to split a string
, with another string being the split by parameter?
我尝试将拆分器转换为字符数组,但没有成功.
I've tried converting the splitter into a character array, with no luck.
换句话说,我想拆分 string
:
In other words, I'd like to split the string
:
THExxQUICKxxBROWNxxFOX
THExxQUICKxxBROWNxxFOX
通过xx
,并返回一个带有值的数组:
by xx
, and return an array with values:
THE、QUICK、BROWN、FOX
THE, QUICK, BROWN, FOX
推荐答案
为了按字符串拆分,您必须使用 字符串数组重载.
In order to split by a string you'll have to use the string array overload.
string data = "THExxQUICKxxBROWNxxFOX";
return data.Split(new string[] { "xx" }, StringSplitOptions.None);
这篇关于在 C# 中用另一个字符串拆分一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中用另一个字符串拆分一个字符串


基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01