2014-09-16 1 views
1

다음 문에서 StringComparison.CurrentCultureIgnoreCase를 사용하는 방법을 알아보십시오. 여기에 배열 요소가 문자열 dummyAccount에 있는지 여부를 확인합니다.다른 문자열의 배열 항목을 검사하는 동안 StringComparison.CurrentCultureIgnoreCase를 사용하는 방법

모든 것이 좋지만 StringComparison.CurrentCultureIgnoreCase 만 사용하려고합니다.

private string getAccount(string dummyAccount) 
{ 
    //e.g dummyAccount="resturant business"; 
    string Account = string.Empty; 

    if ((new string[] { "abc", "Xyz","MD" }).Any(dummyAccount.Contains)) 
    { 
     Account = "Unknown account"; 
    } 
    else if ((new string[] { "shop", "hotel", "Resturant","Business"}).Any(dummyAccount.Contains)) 
    { 
     Account = "Business"; 
    } 
    else if ((new string[] { "school", "college" }).Any(dummyAccount.Contains)) 
    { 
     Account = "University"; 
    } 
    -------------------------------------------------------------- 
    -------------------------------------------------------------- 
    -------------------------------------------------------------- 
    -------------------------------------------------------------- 
    -------------------------------------------------------------- 
    return dummyAccount; 
} 

예컨대
경우 dummyAccount = "음식점 사업";
Account = "Business";

+0

당신은 속임수와 할 수있는 시도'dummyAccount.ToLower는() '(외부 변수를 만들) – Sayse

+0

물론, 모든 배열 항목을 낮은 값으로 변환하고 싶지는 않습니다. –

답변

1

희망 사항. 이 3 배 피하기 위해 경우

private string getAccount(string dummyAccount) 
{ 
    //e.g dummyAccount="resturant business"; 
    string Account = string.Empty; 

    if ((new string[] { "abc", "Xyz", "MD" }).Any(a => dummyAccount.IndexOf(a, StringComparison.InvariantCultureIgnoreCase)>=0)) 
    { 
     Account = "Unknown account"; 
    } 
    else if ((new string[] { "shop", "hotel", "Resturant", "Business" }).Any(a => dummyAccount.IndexOf(a, StringComparison.InvariantCultureIgnoreCase) >= 0)) 
    { 
     Account = "Business"; 
    } 
    else if ((new string[] { "school", "college" }).Any(a => dummyAccount.IndexOf(a, StringComparison.InvariantCultureIgnoreCase) >= 0)) 
    { 
     Account = "University"; 
    } 
    return dummyAccount; 
} 
+0

OP는 dummyAccount에 배열 요소가 들어 있는지 묻습니다. –

+0

답장을 보내 주셔서 감사합니다. ny 배열 요소에 "dummyAccount"문자열이 포함되어 있습니다. –

+0

@SiddiqueMahsud, 답변을 업데이트했습니다.이 기능이 작동하는지 확인해 주시겠습니까? –

-1

당신이 aproach을 시도 할 수 있습니다

private string getAccount(string dummyAccount) 
{ 
    //e.g dummyAccount="resturant business"; 
    string Account = string.Empty; 

    if ((new string[] { "abc", "Xyz","MD" }).Any(s => dummyAccount.ToLower().Contains(s.ToLower()))) 
    { 
     Account = "Unknown account"; 
    } 
    -------------------------------------------------------------- 
    -------------------------------------------------------------- 
    -------------------------------------------------------------- 
    -------------------------------------------------------------- 
    -------------------------------------------------------------- 
    return dummyAccount; 
} 
0

if ((new string[] { "abc", "Xyz", "MD" }).Any(x => dummyAccount.IndexOf(x, StringComparison.CurrentCultureIgnoreCase) >= 0)) 
{ 
    Account = "Unknown account"; 
} 
관련 문제