2017-02-18 2 views
11

나는 TextInfo.ToTitleCase로 변환 한 문자열을 가지고 있으며 밑줄을 제거하고 함께 문자열을 결합했습니다. 이제 문자열의 첫 번째 문자 만 소문자로 변경해야하며 어떤 이유로 든이를 수행하는 방법을 알 수 없습니다. 도움에 미리 감사드립니다.String to CamelCase from TitleCase C#

class Program 
{ 
    static void Main(string[] args) 
    { 
     string functionName = "zebulans_nightmare"; 
     TextInfo txtInfo = new CultureInfo("en-us", false).TextInfo; 
     functionName = txtInfo.ToTitleCase(functionName).Replace('_', ' ').Replace(" ", String.Empty); 
     Console.Out.WriteLine(functionName); 
     Console.ReadLine(); 
    } 
} 

결과 : ZebulansNightmare

원하는 결과 zebulansNightmare는

는 UPDATE :

class Program 
{ 
    static void Main(string[] args) 
    { 
     string functionName = "zebulans_nightmare"; 
     TextInfo txtInfo = new CultureInfo("en-us", false).TextInfo; 
     functionName = txtInfo.ToTitleCase(functionName).Replace("_", string.Empty).Replace(" ", string.Empty); 
     functionName = $"{functionName.First().ToString().ToLowerInvariant()}{functionName.Substring(1)}"; 
     Console.Out.WriteLine(functionName); 
     Console.ReadLine(); 
    } 
} 

답변

18

당신은 단지 배열의 첫 번째 문자를 낮출 필요가 원하는 출력을 생성합니다 . 공백이 제거 당신이 빈 문자열에 밑줄을 대체 할 수있는보고, 측면 참고로이 answer

Char.ToLowerInvariant(name[0]) + name.Substring(1) 

를 참조하십시오.

.Replace("_", string.Empty) 
+0

감사합니다. –

+0

전화하세요. 조정을하고 질문을 업데이트했습니다. –