Anup
Anup

Reputation: 9738

Separate string with comma in 2 different strings

I have 2 scenarios for my string variable.

string qry = "A.PHONE, A.BLOODGRP"; 
or
string qry = "A.PHONE"; 

I want my final result for 1st scenario to be in 2 strings :-

string sort1 = "PHONE";
string sort2 = "BLOODGRP";

I want my final result for 2nd scenario to be in 1 string :-

string sort1 = "PHONE";

How to do this?

Upvotes: 0

Views: 42

Answers (1)

Selman Genç
Selman Genç

Reputation: 101681

You can split on comma and the use Substring to get the part you want:

string qry = "A.PHONE, A.BLOODGRP"; 
var result = qry.Split(',').Select(x => x.Trim().Substring(2)).ToArray();

In the second case just use Substring without split.

Upvotes: 1

Related Questions