.NET 도움말 C# Multiline String (How it Works for Developers) 커티스 차우 업데이트됨:7월 28, 2025 다운로드 IronPDF NuGet 다운로드 DLL 다운로드 윈도우 설치 프로그램 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 When you're getting started in C#, strings are one of the earliest concepts you learn. If you’ve ever put together a Hello, World! program, then you’ve already worked with strings. As you get more familiar with C#, your programs will get more complex. Before long, you’ll start working with strings that span multiple lines. If you’re at that stage now, then you’re in luck, because in this guide, we’ll be explaining what multiline strings are and how to use them. Let’s dive in. What is a Multiline String? Multiline strings are exactly what they sound like - a string that spans multiple lines, contrasting to the usual single-line string. A multiline string in C# is created using string literals, which are a series of characters enclosed in double quotes. To form multiline strings, we need to use a special type of string literals called verbatim string literals. The Magic of Verbatim Strings To create a multiline string literal in C#, we use verbatim strings. Verbatim strings are prefixed with the @ symbol and allow us to include line breaks, special characters, and even whitespace without using escape sequences. Here's an example of a multiline string using a verbatim string: string str = @"This is a multiline string in C#."; string str = @"This is a multiline string in C#."; $vbLabelText $csharpLabel The string str contains three lines, and each line is separated by a line break. Notice the use of the @ symbol to create the verbatim string. Escaping Characters in Verbatim Strings There may be cases where you need to include double quotes within a verbatim string. To do this, you have to use double-double quotes. For example: string str = @"This is a ""multiline"" string in C#."; string str = @"This is a ""multiline"" string in C#."; $vbLabelText $csharpLabel In this example, the string str contains the word "multiline" enclosed in double quotes, which is achieved by using double-double quotes within the verbatim string. Concatenating Multiline Strings You might often need to combine multiline strings with other strings or values. To concatenate a multiline string with other string values, you can use the + operator, just like you would with single-line strings. string name = "John"; string str = @"Hello, " + name + @", Welcome to the world of C# multiline strings!"; string name = "John"; string str = @"Hello, " + name + @", Welcome to the world of C# multiline strings!"; $vbLabelText $csharpLabel Here, we’ve concatenated the multiline string with a single line string name. Formatting Multiline Strings When working with multiline strings, you can format them with variables or expressions. To format a multiline string, you can use the $ symbol for string interpolation. int age = 25; string str = $@"Hello, I am {age} years old, and I am learning C# multiline strings!"; int age = 25; string str = $@"Hello, I am {age} years old, and I am learning C# multiline strings!"; $vbLabelText $csharpLabel We used string interpolation to include the value of the age variable within the multiline string. Converting Multiline Strings to Single Line Strings Sometimes, you may need to convert multiline strings into single line strings. To achieve this, you can use the Replace method to replace line breaks with a space or any other desired character. string multilineString = @"This is a multiline string in C#."; string singleLineString = multilineString.Replace(Environment.NewLine, " "); string multilineString = @"This is a multiline string in C#."; string singleLineString = multilineString.Replace(Environment.NewLine, " "); $vbLabelText $csharpLabel We replaced the line breaks in the multiline string with a space, resulting in a single line string. Handling Long Strings Sometimes, very long strings can are difficult to read in your code. To make the code more readable, you can split long strings into multiple lines using the + operator. string longString = "This is a very long string that " + "needs to be split across " + "multiple lines for better readability."; string longString = "This is a very long string that " + "needs to be split across " + "multiple lines for better readability."; $vbLabelText $csharpLabel We split the long single-line string into three parts and concatenated them using the + operator, making the code more readable. Creating Multiline String Literals with Raw String Literals In C# 10, a new feature was introduced called raw string literals. These allow us to create multiline string literals without using the @ symbol. To create a raw string literal, we enclose the string in triple quotes ("""). Raw string literals preserve all the characters, including line breaks, within the triple quotes. For example: string str = """This is a multiline string using raw string literals in C# 10."""; string str = """This is a multiline string using raw string literals in C# 10."""; $vbLabelText $csharpLabel We created a multiline string using raw string literals. Notice the use of triple quotes to enclose the string. Escaping Characters in Raw String Literals Similar to verbatim strings, we might need to include double quotes within our raw string literals. To do this, we can use double-double quotes. For example: string str = """This is a ""multiline"" string using raw string literals in C# 10."""; string str = """This is a ""multiline"" string using raw string literals in C# 10."""; $vbLabelText $csharpLabel We included double quotes within the raw string literal by using double-double quotes. Combining Verbatim and Raw String Literals In some cases, we may want to combine the features of both verbatim and raw string literals. This can be done by using the @ symbol followed by triple quotes. string str = @"""This is a multiline string using both verbatim and raw string literals in C# 10."""; string str = @"""This is a multiline string using both verbatim and raw string literals in C# 10."""; $vbLabelText $csharpLabel In this example, we created a multiline string using both verbatim and raw string literals. Notice the use of the @ symbol followed by triple quotes. Using Multiline Strings to Generate PDFs in IronPDF IronPDF is a lightweight .NET PDF library designed specifically with web developers in mind. It makes reading, writing, and manipulating PDF files a breeze, able to convert all kinds of file types into PDF content, and you can use it in your .NET projects for both desktop and web. The best part - it’s free to try out in a development environment. Here’s how to utilize an HTML multiline string to create a PDF file in IronPDF: string name = "John"; string age = "25"; string content = $@"<!DOCTYPE html> <html> <body> <h1>Hello, {name}!</h1> <p>You are {age} years old.</p> <p>This is a multiline string used to generate a PDF with IronPDF and dynamic content.</p> </body> </html>"; // Create a new PDF document using IronPDF var pdfDocument = new IronPdf.ChromePdfRenderer(); pdfDocument.RenderHtmlAsPdf(content).SaveAs("c://BioData.pdf"); string name = "John"; string age = "25"; string content = $@"<!DOCTYPE html> <html> <body> <h1>Hello, {name}!</h1> <p>You are {age} years old.</p> <p>This is a multiline string used to generate a PDF with IronPDF and dynamic content.</p> </body> </html>"; // Create a new PDF document using IronPDF var pdfDocument = new IronPdf.ChromePdfRenderer(); pdfDocument.RenderHtmlAsPdf(content).SaveAs("c://BioData.pdf"); $vbLabelText $csharpLabel In this example, we used string interpolation to include the name and age variables within our multiline string, making our PDF content dynamic and customizable. We created a multiline string with the content we wanted in the PDF. We then instantiated the ChromePdfRenderer class from the IronPDF namespace and used the RenderHtmlAsPdf method to convert the multiline string content into a PDF document. Finally, we saved the PDF document to a file called "BioData.pdf". Conclusion And that’s a whistlestop tour of the versatile world of multiline strings. Now you’re a multiline string C# pro, you can start implementing them in your projects - such as the example with IronPDF above. Looking to get your hands on IronPDF? You can start with our 30-day free trial of IronPDF. It’s also completely free to use for development purposes so you can really get to see what it’s made of. And if you like what you see, IronPDF starts as low as $799 for an IronPDF license. For even bigger savings, check out the Iron Suite package where you can get all nine Iron Software tools for the price of two. Happy coding! 자주 묻는 질문 C#에서 여러 줄 문자열을 만들려면 어떻게 해야 하나요? C#에서는 문자열 앞에 '@' 기호를 붙여 축어적 문자열 리터럴을 사용하여 여러 줄 문자열을 만들 수 있습니다. 이렇게 하면 문자열 내에 줄 바꿈과 특수 문자를 직접 포함할 수 있습니다. C#에서 축어 문자열 리터럴을 사용하는 목적은 무엇인가요? C#의 축어적 문자열 리터럴은 이스케이프 시퀀스 없이 줄 바꿈과 특수 문자를 보존하는 문자열을 만드는 데 사용됩니다. '@' 기호로 표시되므로 여러 줄의 문자열을 작성하는 데 이상적입니다. 축어 문자열에서 큰따옴표와 같은 특수 문자는 어떻게 처리하나요? 축어 문자열에서는 큰따옴표를 사용하여 큰따옴표를 포함할 수 있습니다. 예를 들어 '@"이것은 ""여러 줄"" 문자열입니다."'는 문자열 내에 큰따옴표를 포함할 수 있습니다. C# 10에서 원시 문자열 리터럴이란 무엇이며 어떻게 작동하나요? C# 10에 도입된 원시 문자열 리터럴을 사용하면 '@' 기호를 사용하지 않고 여러 줄 문자열을 만들 수 있습니다. 이 문자열은 큰따옴표로 묶여 있으며 줄 바꿈을 포함한 모든 문자가 표시된 그대로 유지됩니다. PDF 생성에 여러 줄 문자열을 어떻게 사용할 수 있나요? 여러 줄 문자열을 사용하여 HTML 형식의 동적 콘텐츠를 만든 다음 HTML에서 PDF로 변환을 지원하는 IronPDF와 같은 라이브러리를 사용하여 PDF 문서로 변환할 수 있습니다. 문자열 보간이란 무엇이며 여러 줄 문자열에 어떻게 적용되나요? C#의 문자열 보간을 사용하면 '$' 기호를 사용하여 문자열 내에 변수나 표현식을 포함할 수 있습니다. 여러 줄 문자열과 함께 사용하여 동적 콘텐츠를 원활하게 포함할 수 있습니다. C#에서 여러 줄 문자열을 한 줄 문자열로 변환하려면 어떻게 해야 하나요? 여러 줄 문자열을 한 줄 문자열로 변환하려면 바꾸기 메서드를 사용하여 줄 바꿈을 공백이나 다른 문자로 바꿀 수 있습니다. 예를 들어 multilineString.Replace(Environment.NewLine, " "). 개발자가 .NET 애플리케이션에서 PDF 생성을 위해 라이브러리를 사용해야 하는 이유는 무엇인가요? IronPDF와 같이 .NET에서 PDF 생성을 위해 설계된 라이브러리는 PDF를 읽고, 쓰고, 조작하는 과정을 간소화합니다. 다양한 파일 유형을 PDF로 변환하여 데스크톱과 웹 애플리케이션 모두를 위한 강력한 툴셋을 제공합니다. 커티스 차우 지금 바로 엔지니어링 팀과 채팅하세요 기술 문서 작성자 커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다. 커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다. 관련 기사 업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기 업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기 업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기 What is Visual C++ RedistributableC# If (How it Works for Developers)
업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기
업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기
업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기