generating GUID without hyphen
I am generating a GUID using the following statement in my code
byte[ ] keyBytes = Encoding.UTF8.GetBytes( Guid.NewGuid( ).ToString( ).Substring( 0, 12 ) );
But, when a GUID is generated, I find that it contains the hyphen character too. How do I go about in generating a GUID with only letters (upper case and lower case) and numbers? I do not want the hyphen. Can someone give me so idea?
Note that you are talking about the (canonical) string representation of a Guid. The Guid itself is actually a 128-bit integer value.
You can use the "N" specifier with the Guid.ToString(String) overload.
Guid.NewGuid().ToString("N");
By default letters are lowercase. A Guid with only uppercase letters can only be achieved by manually converting them all to uppercase, example:
Guid.NewGuid().ToString("N").ToUpper();
A guid with only either letter or digits makes no sense. A guid string representation is hexadecimal, and thus will always (well most likely) contain both.
Guid.NewGuid().ToString().Replace("-", string.Empty)
참고URL : https://stackoverflow.com/questions/8877460/generating-guid-without-hyphen
'programing tip' 카테고리의 다른 글
| React Native에서 로컬 JSON 파일에서 데이터를 가져 오는 방법은 무엇입니까? (0) | 2020.09.11 |
|---|---|
| Linq 구문-여러 열 선택 (0) | 2020.09.11 |
| 백분율 값을 보유하기위한 적절한 데이터 유형? (0) | 2020.09.10 |
| void * a = & a는 어떻게 합법적입니까? (0) | 2020.09.10 |
| 기본 패키지에서 클래스를 가져 오는 방법 (0) | 2020.09.10 |