Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C“字符串操作:来自”;表“U名称”;至;TableName";_C#_String - Fatal编程技术网

C# C“字符串操作:来自”;表“U名称”;至;TableName";

C# C“字符串操作:来自”;表“U名称”;至;TableName";,c#,string,C#,String,最好的方法是什么 尝试过这样的事情: public String FormatColumnName(String columnName) { String formatedColumnName = columnName.Replace('_', ' ').Trim(); StringBuilder result = new StringBuilder(formatedColumnName); result[0] = char.ToUpper(result[0]);

最好的方法是什么

尝试过这样的事情:

public String FormatColumnName(String columnName)
{
    String formatedColumnName = columnName.Replace('_', ' ').Trim();
    StringBuilder result = new StringBuilder(formatedColumnName);
    result[0] = char.ToUpper(result[0]);
    return result.ToString();
}
对我不起作用,也许有人能给我一个干净的解决方案,告诉我怎么做。

怎么样:

string result = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(
       columnName.Replace('_', ' ').Trim().ToLower()).Replace(" ","");

ToTitleCase
将“小写单词”更改为“小写单词”(但不触及大写),因此需要
ToLower
-然后我们用
Replace
String.Concat(columnName.Split(“')。选择(s=>s[0]+s.Substring(1.ToLower()))
删除空格,结果是TABLENAME,我以前也试过类似的东西,也没有work@eMi我刚刚测试过,效果很好;请刷新。。。(我确实编辑)我猜它是正确的,但是.Times()不会在字符串中间删除“”,所以空白应该被替换。不过,它可以很好地与“TableName”和“TableName”@eMi配合使用,它不仅可以工作,而且可读性更强。也许效率会更高,但因为我不太熟悉林克,我更喜欢马克的版本。
string str = "TABLE_NAME";

string str2 = string.Join("", str.Split('_').Select(p => char.ToUpper(p[0]) + p.Substring(1).ToLower()));