标签: string-operations

在 C# 中检查字符串是半宽还是全宽

日语 Windows 操作系统上的 C# 应用程序 - 将拉丁语显示为全角字符

我在上面的链接中引用了接受的答案,并使用下面的代码将日语字符串从全宽转换为半宽,但它返回相同的全宽字符串而不进行转换。

string userInput = "??????????";
string result = userInput.Normalize(NormalizationForm.FormKC);
Run Code Online (Sandbox Code Playgroud)

半宽的预期输出:?????????? 实际输出:?????????? (全屏宽度)

但是,即使上面的代码应该将全角字符串转换为半角,当我将半角字符串 (??????????) 传递给上面的代码时,它也会将其转换为全角形式(????????????)。

我在这里做错了什么?

无论如何,如果我的字符串已经是半角,我不希望执行上面的代码。

如何检查字符串是半宽还是全宽?

c# asp.net string-conversion asp.net-core string-operations

5
推荐指数
1
解决办法
2217
查看次数

使用Java字符串操作删除查询参数

我有一个简单的问题,但尚未找到最佳解决方案。

想象一下,我有一个带有名为“ id”的查询参数的URL,类似于以下任何一种格式

  • xxxxxxxxxxxxx?id = 123
  • xxxxxxxxxxxxx?id = 123&xxxxxxxx
  • xxxxxxxxxxxxx?xxxxxx&id = 123
  • xxxxxxxxxxxxx?xxxxxx&id = 123&xxxxx

我将上面的字符串(可以是上面的任何一个)作为String参数,并想找出删除查询参数id(名称和值)的最简单方法,因此即使删除后,它也是有效的url 。

以下是我的预期输出(按顺序)。

  • xxxxxxxxxxxxx
  • xxxxxxxxxxxxx?xxxxxxxx
  • xxxxxxxxxxxxx?xxxxxx
  • xxxxxxxxxxxxx?xxxxxx&xxxxx

谁能有个好主意?(仅适用于String操作,没有任何util类)

java string url query-parameters string-operations

3
推荐指数
1
解决办法
192
查看次数

如何在python中检查一行是否是一个有效的函数调用?

背景:我正在为ipython创建一个魔术线.这种魔法只适用于行,其中函数的返回值被赋给变量.

我正在寻找一种方法来确保一行是python中有效的函数调用+赋值.

例如,接受以下内容:

a = b()
a,b = c(d,e="f")
a = b(c()+c)
Run Code Online (Sandbox Code Playgroud)

以下内容将被拒绝:

a = def fun() # no function call
b(a=2) # no assignment
a = b + c # no function call 
a = b() + c() # top-level on right-hand-side must be function call
Run Code Online (Sandbox Code Playgroud)

如果该行根本不是有效的python,我不关心它是否通过,因为这将在另一个阶段处理.

python regex parsing string-operations

2
推荐指数
1
解决办法
407
查看次数

如何替换部分未知字符串


我需要替换(或更好地删除)字符串,在此我知道开始和结束。
有些字符是未知的,字符串的长度也是未知的。
当然,我可以使用子字符串和其他c#字符串操作,但是没有简单的替换通配符选项吗?

mystring.Replace("O(*)", "");
Run Code Online (Sandbox Code Playgroud)

Would be a nice Option.
I know that the string Begins with O( and Ends with ).
It's possible than the String Looks like O(something);QG(anything else)
Here the result should be ;QG(anything else)

Is this possible with a simple replace?
And what About the advanced Option, that he string exists more than one time like here:
O(something);O(someone);QG(anything else)

c# string-operations

1
推荐指数
1
解决办法
42
查看次数

如何用多个字符拆分字符串?

我有一个这样的字符串:string ip = "192.168.10.30 | SomeName".我想把它拆分|(包括空格.不幸的是,使用这段代码不可能:

string[] address = ip.Split(new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
Run Code Online (Sandbox Code Playgroud)

因为这会导致"192.168.10.30 ".我知道我可以添加.Trim(),address[0]但这是非常正确的方法吗?

简单地将空格(' | ')添加到搜索模式给了我一个

无法识别的转义序列

.net c# string split string-operations

-2
推荐指数
1
解决办法
2019
查看次数