Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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#.
Posted
Updated 27-Jul-16 19:49pm

One method is as follows;
C#
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 [^]
 
Share this answer
 
v2
Just split using '('

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900