小编isH*_*man的帖子

使用IndexOf和CultureInfo 1031的ArgumentOutOfRangeException

string s = "Gewerbegebiet Waldstraße"; //other possible input "Waldstrasse"

int iFoundStart = s.IndexOf("strasse", StringComparison.CurrentCulture);
if (iFoundStart > -1)
    s = s.Remove(iFoundStart, 7);
Run Code Online (Sandbox Code Playgroud)

我正在运行CultureInfo 1031(德语).

IndexOf将'straße'或'strasse'与定义的'strasse'匹配,并返回18作为位置.

删除和替换都没有设置文化的任何重载.

如果我删除6个字符使用删除1字符将保留,如果输入字符串是'strasse'和'straße'将工作.如果输入字符串是'straße'并且我删除了7个字符,则会得到ArgumentOutOfRangeException.

有没有办法安全地删除找到的字符串?提供IndexOf的最后一个索引的任何方法?我更接近IndexOf,它的本机代码正如预期的那样 - 所以没办法做自己的事......

c# exception indexof currentculture

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

标签 统计

c# ×1

currentculture ×1

exception ×1

indexof ×1