首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以将Hello.World转换为["Hello"]["World"]?

是否可以将Hello.World转换为["Hello"]["World"]?
EN

Stack Overflow用户
提问于 2020-08-18 14:00:23
回答 2查看 166关注 0票数 0

我想知道是否有一种转换示例的方法:

'Hello.World' into ‘“Hello”或 or “This”a

我对C#有点陌生,我想知道是否可以使用字符串格式或类似的东西。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-18 14:02:36

您可以使用类似于此的Split方法,string[] strings = String.Split(".");,这将使每个句点拆分您的字符串。

票数 3
EN

Stack Overflow用户

发布于 2020-08-18 14:05:17

如果您打算将单引号(')作为字符串的一部分,那么:

代码语言:javascript
复制
String test = "'Hello.World'";
// Strip the first and last '
test = test.Substring(1, test.Length - 2);
// Split on Period
String[] split = test.Split('.');
// Encapsulate each word with [" "]
// and add back in the single quotes
var result = $"'{String.Join("", split.Select(word => $"[\"{word}\"]"))}'";

印刷品:“你好”

如果他们只是想包围你的输入,那么就:

代码语言:javascript
复制
String test = "Hello.World";
// Split on Period
String[] split = test.Split('.');
// Encapsulate each word with [" "]
var result = $"{String.Join("", split.Select(word => $"[\"{word}\"]"))}";

印刷品:“你好”

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63470295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档