串工作不正常,如果长度大于字符串的长度 [英] Substring not working as expected if length greater than length of String

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

问题描述

好球员,我知道如果/其他工作,我需要一种替代方法。

Ok guys, I know if/else works, i needed an alternative.

我使用

B = String.Concat(A.Substring(0, 40));

捕捉值的前40个字符。

to capture the first 40 characters of a value.

如果在 A 的值大于 40 B 是能够捕捉到,但如果值 A 小于 40 ,没有值为在捕获乙

If the value at A is more than 40, B is able to capture, but if the value of A is less than 40, there is no value being captured at B.

推荐答案

不理解只通过单一的字符串String.Concat的目的。你的目的,可以通过解决:

Not understanding the purpose of passing only single string in String.Concat. Your purpose can be solved by:

if(A.Length > 40)
       B= A.Substring(0,40);
else
       B=A;

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

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