如何分割信( [英] How to split letter (

查看:135
本文介绍了如何分割信(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下



string vehciletype = value.Tables [0] .Rows [0]。[VehicleType]。tostring();



程序输出如下





VehicleType



TNOPA232 - Indica(4座)





从上面我要输出如下



TNOPA232 - Indica



我怎么能用asp.net C#。



我尝试过:



我的代码如下



字符串vehciletype = value.Tables [0] .Rows [0]。[VehicleType]。tostring();



在程序输出中如下





VehicleType



TNOPA232 - Indica (4座)





从上面我要输出如下



TNOPA232 - Indica



我怎么能用asp.net C#。

解决方案

一种方法如下;

  string  vehicletype =  value 。表[ 0 ]。行[ 0 ] [  VehicleType]。toString()
string strTrimmedString;
int intBracket = vehicletype.IndexOf( );
if (intBracket > -1)
{
strTrimmedString = vehicletype.Substring( 0 ,intBracket);
}
else
{
strTrimmedString = vehicletype;
}



字符串的MSDN参考 [ ^ ]


只需使用''''拆分/>


  string  text =    TNOPA232  -  Indica(4seater); 
string result = text.Split ( ' (')[ 0 ]。的ToString();


My code as follows

string vehciletype= value.Tables[0].Rows[0].["VehicleType"].tostring();

In procedure output as follows


VehicleType

TNOPA232 - Indica (4seater)


From the above one i want output as follows

TNOPA232 - Indica

for that how can i do in asp.net C#.

What I have tried:

My code as follows

string vehciletype= value.Tables[0].Rows[0].["VehicleType"].tostring();

In procedure output as follows


VehicleType

TNOPA232 - Indica (4seater)


From the above one i want output as follows

TNOPA232 - Indica

for that how can i do in asp.net C#.

解决方案

One method is as follows;

string vehicletype = value.Tables[0].Rows[0]["VehicleType"].toString()
string strTrimmedString;
int intBracket = vehicletype.IndexOf("(");
if(intBracket > -1)
{
    strTrimmedString = vehicletype.Substring(0, intBracket);
}
else
{
    strTrimmedString = vehicletype; 
}


MSDN Reference on Strings [^]


Just split using '('

string text = "TNOPA232 - Indica (4seater)";
string result = text.Split('(')[0].ToString();


这篇关于如何分割信(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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