在C#中左功能 [英] Left function in c#

查看:146
本文介绍了在C#中左功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:结果
。老左VB(字符串,长度)的功能相当于净?






什么是C#
I的替代方案Left函数有这样的

 左(fac.GetCachedValue(自动打印临床警告)ToLower将+,1 ==)。Y); 


解决方案

这听起来像你问的函数

 字符串左(字符串s,诠释左)

这将返回字符串最左边的离开字符取值。在这种情况下,你可以使用 String.Substring 。你可以写这是一个扩展方法:

 公共静态类StringExtensions 
{
公共静态字符串左(此字符串值,INT最大长度)
{
如果(string.IsNullOrEmpty(值))的返回值;
=最大长度Math.Abs​​(最大长度);

回报率(value.Length< =最大长度

:value.Substring(0,最大长度)
);
}
}

和使用它像这样:

 字符串左= s.Left(号); 

有关您的具体的例子:



<$ P $ 。p> 字符串s = fac.GetCachedValue(自动打印临床警告)ToLower将()+;
串左= s.Substring(0,1);


Possible Duplicate:
.Net equivalent of the old vb left(string, length) function?

what is the alternative for Left function in c# i have this in

Left(fac.GetCachedValue("Auto Print Clinical Warnings").ToLower + " ", 1) == "y");

解决方案

It sounds like you're asking about a function

string Left(string s, int left)

that will return the leftmost left characters of the string s. In that case you can just use String.Substring. You can write this as an extension method:

public static class StringExtensions
{
    public static string Left(this string value, int maxLength)
    {
        if (string.IsNullOrEmpty(value)) return value;
        maxLength = Math.Abs(maxLength);

        return ( value.Length <= maxLength 
               ? value 
               : value.Substring(0, maxLength)
               );
    }
}

and use it like so:

string left = s.Left(number);

For your specific example:

string s = fac.GetCachedValue("Auto Print Clinical Warnings").ToLower() + " ";
string left = s.Substring(0, 1);

这篇关于在C#中左功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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