修剪字符串并将其转换为小写的最快方法 [英] Fastest way to trim a string and convert it to lower case

查看:82
本文介绍了修剪字符串并将其转换为小写的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个用于处理字符串的类,但遇到了以下问题:传入的字符串在字符串的开头和结尾可能带有空格。

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();

这篇关于修剪字符串并将其转换为小写的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆