알쓸전컴(알아두면 쓸모있는 전자 컴퓨터)
C# sql 특수 문자 처리 본문
C# sql 특수 문자 처리
아래가 sql 에서 특수 문자 처리를 위한 컨버터 함수 입니다.
자주 사용하게 될것 같아 글을 남깁니다.
public string AddSlashes(string InputTxt)
{
// List of characters handled:
// \000 null
// \010 backspace
// \011 horizontal tab
// \012 new line
// \015 carriage return
// \032 substitute
// \042 double quote
// \047 single quote
// \134 backslash
// \140 grave accent
string Result = InputTxt;
try
{
Result = System.Text.RegularExpressions.Regex.Replace(InputTxt, @"[\000\010\011\012\015\032\042\047\134\140]", "\\$0");
}
catch (Exception Ex)
{
// handle any exception here
Console.WriteLine(Ex.Message);
}
return Result;
}
public static string StripSlashes(string InputTxt)
{
// List of characters handled:
// \000 null
// \010 backspace
// \011 horizontal tab
// \012 new line
// \015 carriage return
// \032 substitute
// \042 double quote
// \047 single quote
// \134 backslash
// \140 grave accent
string Result = InputTxt;
try
{
Result = System.Text.RegularExpressions.Regex.Replace(InputTxt, @"(\\)([\000\010\011\012\015\032\042\047\134\140])", "$2");
}
catch (Exception Ex)
{
// handle any exception here
Console.WriteLine(Ex.Message);
}
return Result;
}
'C# tip' 카테고리의 다른 글
Smtp 메일 전송 방법 (0) | 2018.11.16 |
---|---|
CefSharp chrome run javascript (0) | 2018.08.13 |
Datatable Merge(병합) 하기 (0) | 2018.07.19 |
Datatable 을 csv (엑셀)출력 하는 소스 (0) | 2018.07.19 |
mono linux 최신 버전 build 하기 (0) | 2018.07.11 |
Comments