我正在使用以下 C# 代码在单引号后将小写字母修改为大写:
public virtual string FirstName
{
get { return _firstName; }
set
{
if (value != null)
{
int pos = value.IndexOf("'", 0);
int strlength = value.Length - 1;
if (pos >= 0 && pos != strlength)
{
string temp = value[pos + 1].ToString();
temp = temp.ToUpper();
value = value.Remove(pos + 1, 1);
value = value.Insert(pos + 1, temp);
}
}
}
}
对我来说,这看起来有点矫枉过正。有没有更简单的方法来达到预期的结果:
Value: Mc'donald
Expected: Mc'Donald