必须有更好的方法来处理字符串字符 [英] There has to be a better way to work withat string chars
本文介绍了必须有更好的方法来处理字符串字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要取一个字符串,将第一个字符设为小写并在其前面添加一个
下划线字符。这样的事情:
" California"
这是我提出的(丑陋)解决方案with:
I need to take a string, make the first character lowercase and prepend an
underscore character to it. Something like this:
"California"
"_california"
Here is the (ugly) solution I cam up with:
展开 | 选择 | Wrap | 行号
推荐答案
sklett,
我不明白为什么那是丑陋的。代码非常自我描述,
表明你正在做什么。
AFAIK,没有更好的方法来做到这一点。您可以使用
StringBuilder,并执行以下操作:
公共静态字符串MakeNetSuiteStateName(字符串normalStateName)
{
//返回值。
StringBuilder retVal = new StringBuilder(" _" + normalStateName);
//小写第二个字符。
retVal [1] = retval [1] .ToLower();
//返回字符串。
返回retVal.ToString();
}
希望这会有所帮助。
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard .caspershouse.com
" sklett" < s@s.com写了留言
新闻:uQ ************** @ TK2MSFTNGP06.phx.gbl ...
sklett,
I don''t see why that is ugly. The code is pretty self-descriptive,
indicating exactly what you are doing.
AFAIK, there isn''t a much better way to do this. You could use a
StringBuilder, and do this:
public static string MakeNetSuiteStateName(string normalStateName)
{
// The return value.
StringBuilder retVal = new StringBuilder("_" + normalStateName);
// Lower-case the second character.
retVal[1] = retval[1].ToLower();
// Return the string.
return retVal.ToString();
}
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"sklett" <s@s.comwrote in message
news:uQ**************@TK2MSFTNGP06.phx.gbl...
>我需要取一个字符串,将第一个字符设为小写并在其前面添加一个
下划线字符。这样的事情:
" California"
这是我提出的(丑陋)解决方案with:
>I need to take a string, make the first character lowercase and prepend an
underscore character to it. Something like this:
"California"
"_california"
Here is the (ugly) solution I cam up with:
展开 | 选择 | Wrap | 行号
" sklett" < s@s.com写了留言
新闻:uQ ************** @ TK2MSFTNGP06.phx.gbl ...
|我需要取一个字符串,将第一个字符设为小写并添加一个
|强调它的性格。这样的事情:
| 加利福尼亚
| _california
|
|这是我提出的(丑陋)解决方案:
|
"sklett" <s@s.comwrote in message
news:uQ**************@TK2MSFTNGP06.phx.gbl...
|I need to take a string, make the first character lowercase and prepend an
| underscore character to it. Something like this:
| "California"
| "_california"
|
| Here is the (ugly) solution I cam up with:
|
展开 | 选择 | Wrap | 行号
" Willy Denoyette [MVP]" < wi ************* @ telenet.bewrote in message
news:uu **************** @ TK2MSFTNGP04.phx.gbl ...
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:uu****************@TK2MSFTNGP04.phx.gbl...
>
" sklett" < s@s.com写了留言
新闻:uQ ************** @ TK2MSFTNGP06.phx.gbl ...
|我需要取一个字符串,使第一个字符小写并且前置
一个
|强调它的性格。这样的事情:
| 加利福尼亚
| _california
|
|这是我提出的(丑陋)解决方案:
|
>
"sklett" <s@s.comwrote in message
news:uQ**************@TK2MSFTNGP06.phx.gbl...
|I need to take a string, make the first character lowercase and prepend
an
| underscore character to it. Something like this:
| "California"
| "_california"
|
| Here is the (ugly) solution I cam up with:
|
展开 | 选择 | Wrap | 行号
这篇关于必须有更好的方法来处理字符串字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文