Jango
Jango

Reputation: 5545

how to substring from a string using c#

The following is a line of huge .txt file and i am reading it line by line. I need the value of second column. In this line, I need to extract 'C9006'.

Mr ABC|C9006|The white field, ON|493-493-4939|493-493-4939|YR|Inactive

Note : The delimiter char is pipe sign '|'. The length of second column is not consistent.

Help please.

Upvotes: 0

Views: 695

Answers (3)

Robert Christie
Robert Christie

Reputation: 20685

String value = "A|B|C";
String secondColumn = value.split("|")[1];

Upvotes: 3

Aviad P.
Aviad P.

Reputation: 32629

string result = input.Split('|')[1];

Upvotes: 1

Laurent Etiemble
Laurent Etiemble

Reputation: 27889

You can use the Split method of String.

Upvotes: 1

Related Questions