728x90
반응형
Replace 를 사용하여, "\n" 대신 "\\n" 를 넣는다.
using System;
using System.Web;
namespace YourNamespace
{
public class YourClass
{
public void YourMethod()
{
// Get the current HttpContext
HttpContext context = HttpContext.Current;
// Set the content type of the response
context.Response.ContentType = "text/html";
// Construct the message with line breaks
string sMsg = "안녕하세요.\n환영합니다";
// Write the JavaScript alert with the formatted message
context.Response.Write(string.Format("alert('{0}');", sMsg.Replace("\n", "\\n")));
// End the response
context.Response.End();
}
}
}
출처 | chatGPT
728x90
반응형
'.NET' 카테고리의 다른 글
C# 만나이 계산 방법 (chatGPT) (0) | 2023.08.01 |
---|---|
System.Data.SqlClient.SqlParameter 를 사용하여 nvarchar(max) 코드 설정하는 방법 (chatGPT) (0) | 2023.07.30 |
static 을 왜 사용하는가, 사용하는 이유 (ChatGPT) (0) | 2023.07.27 |
C# 에서 컴퓨터 이름 가져오기 (ChatGPT) (0) | 2023.07.23 |
Request.Url.AbsoluteUri, Request.Path, Request.RawUrl 차이 (ChatGPT) (0) | 2023.06.19 |