字符串长度 [英] string length

查看:82
本文介绍了字符串长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个查询字符串中分配了一个字符串


公共字符串a = request.querystring [1]


我该怎么办?确保字符串a小于250个字符?不使用if''s

aaron

I have a string assigned a value from a querystring

public string a = request.querystring[1]

how can i make sure string a is less than 250 char? without using if''s
aaron

推荐答案

除非你愿意将三元运算符与不同于一个

如果,那么我似乎无法想到一个。


我在想这样的事情:


(a.length <250)? a:a.Substring(0,250)


我知道它基本上是一个if,但是你可以把它放在有条件或

任何其他声明中,如果这就是你需要避免ifs的原因。

其他字符串函数似乎太高兴做任何事情

创意了。与StringBuilder相同。


Dave
Unless you''re willing to count the ternary operator as different from an
if, then I can''t seem to think of one.

I''m thinking of something like this:

(a.length < 250) ? a : a.Substring(0,250)

I know it''s basically an if, but you can put it inside a conditional or
any other statement, if that''s why you need to avoid ifs.

The other string functions seem to be too exception happy to do anything
to creative with. Same with StringBuilder.

Dave


除非你愿意将三元运算符与

如果,那么我似乎无法想到一个。


我想的是这样的:


(a.length <250)? a:a.Substring(0,250)


我知道它基本上是一个if,但是你可以把它放在有条件或

任何其他声明中,如果这就是你需要避免ifs的原因。

其他字符串函数似乎太高兴做任何事情

创意了。与StringBuilder相同。


Dave
Unless you''re willing to count the ternary operator as different from an
if, then I can''t seem to think of one.

I''m thinking of something like this:

(a.length < 250) ? a : a.Substring(0,250)

I know it''s basically an if, but you can put it inside a conditional or
any other statement, if that''s why you need to avoid ifs.

The other string functions seem to be too exception happy to do anything
to creative with. Same with StringBuilder.

Dave


public string a = Request.QueryString [2] .Substring(0,250);

-

____________________

Klaus H. Probst,MVP
http://www.vbbox.com/

" Aaron" <ク***** @ yahoo.com>在消息中写道

news:e1 ************** @ TK2MSFTNGP10.phx.gbl ...
public string a = Request.QueryString[2].Substring(0, 250);
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Aaron" <ku*****@yahoo.com> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
我分配了一个字符串来自查询字符串的值

公共字符串a = request.querystring [1]

如何确保字符串a小于250个字符?不使用if''s

aaron
I have a string assigned a value from a querystring

public string a = request.querystring[1]

how can i make sure string a is less than 250 char? without using if''s
aaron



这篇关于字符串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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