问题描述
我编写了一个用于处理字符串的类,但遇到了以下问题:传入的字符串在字符串的开头和结尾可能带有空格。
I've written a class for processing strings and I have the following problem: the string passed in can come with spaces at the beginning and at the end of the string.
我需要修剪字符串中的空格并将其转换为小写字母。到目前为止,我的代码是:
I need to trim the spaces from the strings and convert them to lower case letters. My code so far:
var searchStr = wordToSearchReplacemntsFor.ToLower();
searchStr = searchStr.Trim();
在 StringBuilder 。问题在于,此类应该尽可能快地处理许多字符串。因此,我不想为课程处理的每个字符串创建2个新字符串。
I couldn't find any function to help me in
StringBuilder
. The problem is that this class is supposed to process a lot of strings as quickly as possible. So I don't want to be creating 2 new strings for each string the class processes.
如果不可能,我将更深入地介绍处理算法。
If this isn't possible, I'll go deeper into the processing algorithm.
推荐答案
尝试方法链接。
例如:
var s = " YoUr StRiNg".Trim().ToLower();
这篇关于修剪字符串并将其转换为小写的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!