2016-07-13 12 views
1

入力1表示ラベル

列STR =」1 KAUSHAL Duttaさん46雌WL 19 WL 2" 上の文字列の一部。

入力2

列STR1 = "1アヤンPAL 38雄CNF S5 49(LB)CNF S5 49(LB)"。

iは、ユーザが文字列strを入力した場合、出力は(WL 2)でなければならない文字列の二つの異なるタイプがあり&ユーザが文字列STR1を入力した場合、出力は(CNF S5 49(LB))

なければなりません

すべての値が(WL(数))を除き、動的です(CNF(1アルファベット1 または2の数)数(LB))

+0

あなたの質問は何ですか?どのプログラミング言語を使用しますか? –

+0

私はC#asp.netを使用しています –

+1

あなたの目的を明確にする必要があります。まともな例を共有することもできます – Progressive

答えて

0

あなたの入力文字列は、いくつかの区切り文字でフレーム場合は、簡単にできます文字列を分割すると、配列に格納して処理することができます。例えば

、 "WL 2 @女性@ WL 19 @ 46 @ KAUSHAL Duttaさん@ 1"

文字列str =として、あなたの文字列をフレーム。

これは[] STR1 = str.Split( '@')

文字列のような文字列を分割した後、

str1の配列から、あなたは最後の値のSTR1を取ることができます[5]

0

あなたは正規表現を使用することができます。 https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx

//This is the pattern for the first case WL followed by a one or more (+) digits (\d) 
//followed by any number of characters (.*) 
//the parenthesis is to us to be able to group what is inside, for further processing 
string pattern1 = @"WL \d+ (.*)"; 

//Pattern for the second match: CNF followed by a letter (\w) followed by one or two ({1,2}) 
//digits (\d) followed by one or more (+) digits (\d), followed by (LB) "\(LB\)" 
//the backslach is to get the litteral parenthesis 
//followed by any number of characters (.*) 
//the parenthesis is to us to be able to group what is inside, for further processing 
string pattern2 = @"CNF \w\d{1,2} \d+ \(LB\) (.*)"; 

string result=""; 

if (Regex.IsMatch(inputString, pattern1)) 
{ 
    //Groups[0] is the entire match, Groups[1] is the content of the first parenthesis 
    result = Regex.Match(inputString, pattern1).Groups[1].Value; 
} 
else if (Regex.IsMatch(inputString, pattern2)) 
{ 
    //Groups[0] is the entire match, Groups[1] is the content of the first parenthesis 
    result = Regex.Match(inputString, pattern2).Groups[1].Value; 
} 
関連する問題