posted by 준치 2018. 2. 1. 17:11

c# 으로 문자열 앞에 0을 채워야 할 경우가 있고... 특정 문자를 채워야 할 때가있다...


이럴때 PadLeft 또는 PadRight 를 사용하면 된다.


사용 방법


string str = "test";

char pad = '0';


str.PadLeft(전체 자릿수 , pad)

또는

str.PadRight(전체 자릿수 , pad)


전체 자릿수에 10 넣을 경우 결과 값

- str.PadLeft(전체 자릿수 , pad) : 000000test

- str.PadRight(전체 자릿수 , pad) : test000000


사용할때 마다 검색 한듯.... 


출처 : https://msdn.microsoft.com/ko-kr/library/36f2hz3a(v=vs.110).aspx

출처 : https://msdn.microsoft.com/ko-kr/library/92h5dc07(v=vs.110).aspx


ToString을 사용하는 방법도 있다.


참고 : https://msdn.microsoft.com/ko-kr/library/dd260048(v=vs.110).aspx


오늘도 화이팅...

SQL
posted by 준치 2014. 5. 22. 17:35

메시지 보내는 간단한 작업을 하는데 입력하는 순간 에러가 발생한다.

에러 메시지는 "문자열이나 이진 데이터는 잘립니다."

내 상황에서는 간단하게 처리되었다.

원인

입력되는 컬럼의 크기보다 데이터가 더 많아서 생긴 문제였다.

해결

컬럼의 크기를 크게 잡거나 데이터를 줄이거나 선택.

오늘도 화이팅.

posted by 준치 2009. 2. 10. 22:27

var str = "http://yahoo.co.kr";

document.write(str.match(/http/));
document.write(str.replace(/http/,"timo")); 

document.write(str.match(/^t/));
 // ^ : t로 시작하는 문자열, str은 h 로 시작하므로 null 반환
document.write(str.replace(/^h/,"hahaha"));
// hahahattp://yahoo.co.kr 

document.write(str.match(/t$/));
// $ : t로 끝나는 문자열, str은 r 로 끝나므로 null 반환

document.write(str.replace(/r$/,"kakaka"));

// http://yahoo.co.kkakaka 
// . \n 을 제외한 한 문자
document.write(str.match(/.r/));
// . : 문자 + r 조합으로 이루어진 문자열 kr 반환
document.write(str.match(/h./));
// h + 문자 조합으로 이루어진 문자열 ht 반환
document.write(str.match(/h.t/)); 
// h + 문자 + t 조합으로 이루어진 문자열 htt 반환
str = "ooaaadddccadooaddd"
document.write(str.match(/d*d/g));
// * : d 앞에 d 가 0번 이상 나오는 문자열. ddd,d,ddd 반환
document.write(str.replace(/d*d/g,"__"));
//  ooaaa__cc__oo__ 
str = "xxxyyyxyz";
document.write(str.match(/xy?z/g));
// ? : z 앞의 문자 y 가 없거나 딱한번 있는 문자열 xyz 반환
document.write(str.replace(/xy?z/g,"_"));
// xxxyyy_  
str = "xxxyyyxyyyyyz";
document.write(str.match(/xy+z/g));
// + : z 앞의 문자 y 가 한번 이상 있는 문자열 xyyyyyz  반환
document.write(str.replace(/xy+z/g,"_"));
// xxxyyy_ 

[] : 괄호안의 !!문자!!나 !!숫자!!중 !!하나에!! 해당되면 참

document.write(str.match(/[xyz]/g));

// x,x,x,y,y,y,x,y,y,y,y,y,z


document.write(str.replace(/[xyz]/g,"_"));

// _____________

 

str = "ab12cd";

document.write(str.match(/ab[12]cd/g));

// [] 기호는 한개의 문자에 매치되므로 결과는 null

// ab1cd 이거나 ab2cd 인 문자열에 매치된다. 

str = "ab1cd";

document.write(str.match(/ab[12]cd/g));

// [] 기호는 한개의 문자에 매치되므로 결과는 ab1cd  

document.write(str.match(/ab[^12]cd/g));

// ab1cd 가 아니거나 ab2cd 가 아닌 문자열을 찾는다. 결과는 null 

document.write(str.match(/ab[^34]cd/g));

// ab3cd 가 아니거나 ab4cd 가 아닌 문자열을 찾는다. 결과는 ab1cd


{} 괄호앞의 !!문자!! 가 반복된 횟수를 의미 , 숫자만 들어갈 수 있다.


str = "xxxyyyz";

document.write(str.match(/x{3}y/g));

// x가 3번 반복된 문자열을 찾는다. 결과는 xxxy


document.write(str.match(/x{1,}y/g));

// x가 1번 이상 반복된 문자열을 찾는다. 결과는 xxxy


document.write(str.match(/x{0,3}y/g));

// x가 0번 이상 3번 이하 반복된 문자열을 찾는다. 결과는 xxxy,y,y


() 괄호안의 문자열을 참조 단독으로 쓰지 않고 *,+,? 등과 조합해서 사용된다.
str = "xyayayaz";

document.write(str.match(/x(ya)*z/g)); //==> xyayayaz  

str = "xxxxxabcabczzzzz";
document.write(str.match(/x(abc)*z/g));

// *는 z앞의 문자가 없거나 한번 이상 있는 경우를 나타내므로 결과는  xabcabcz


document.write(str.match(/x(abc)?z/g));

// ?는 z앞의 문자가 없거나 딱 한번 있는 경우를 나타내므로 결과는 null


document.write(str.match(/x(abc)+z/g));

// +는 z앞의 문자가 한번 이상 있는 경우를 나타내므로 결과는 xabcabcz
document.write(str.match(/x(abc){0,2}z/g));

// xabcabcz
document.write(str.match(/x(ab|cd){0,2}z/g));

// xabcabcz  

str = "http://naver.com http://na http://nav";
document.write(str.match(/(http:\/\/[a-zA-Z0-9\.]{1,})/g));

// http://naver.com,http://na,http://nav  

document.write(str.replace(/(http:\/\/[a-zA-Z0-9\.]{1,})/g,"*"));

// * * *
document.write(str.match(/(http:\/\/[a-zA-Z0-9\.]{10,})/g));

// null
[이메일]
-이메일 형식을 검색
/\w+@\w+\.\w+/g 

[숫자]
-숫자가 아닌 문자를 검색
/\D+/g 

[이름]
-이름에 숫자나 특수문자가 들어갔는지 검증
/[^a-zA-Z]+/g

/[^a-zA-Z가-하]+/g

정규식을 바로 테스트 해 볼수 있는 사이트

http://www.roblocher.com/technotes/regexp.aspx

http://blog.naver.com/liba2000?Redirect=Log&logNo=140052579331