我想知道是否有一种转换示例的方法:
'Hello.World' into ‘“Hello”或 or “This”a
我对C#有点陌生,我想知道是否可以使用字符串格式或类似的东西。
发布于 2020-08-18 14:02:36
您可以使用类似于此的Split方法,string[] strings = String.Split(".");,这将使每个句点拆分您的字符串。
发布于 2020-08-18 14:05:17
如果您打算将单引号(')作为字符串的一部分,那么:
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}\"]"))}'";印刷品:“你好”
如果他们只是想包围你的输入,那么就:
String test = "Hello.World";
// Split on Period
String[] split = test.Split('.');
// Encapsulate each word with [" "]
var result = $"{String.Join("", split.Select(word => $"[\"{word}\"]"))}";印刷品:“你好”
https://stackoverflow.com/questions/63470295
复制相似问题