1. 현재 날짜
[VB6]
TextBox1.Text = Format(Now, "yyyy/mm/dd")
[VB.NET] 자동변환
TextBox1.Text = String.Format(Now, "yyyy/mm/dd")
문제점 → 시분초까지 표시됨
[VB.NET] 수정
TextBox1.Text = Now.ToString("yyyy/MM/dd")
주의 → MM을 mm으로 표시하면 그대로 분이 출력됨
2. LeftB, MidB, RightB
선언
사용예
3. LenB
선언
사용예
[VB6]
TextBox1.Text = Format(Now, "yyyy/mm/dd")
[VB.NET] 자동변환
TextBox1.Text = String.Format(Now, "yyyy/mm/dd")
문제점 → 시분초까지 표시됨
[VB.NET] 수정
TextBox1.Text = Now.ToString("yyyy/MM/dd")
주의 → MM을 mm으로 표시하면 그대로 분이 출력됨
2. LeftB, MidB, RightB
선언
Public Class VBStrings
Public Shared Function LeftB(ByVal stTarget As String, ByVal iByteSize As Integer) As String
Return MidB(stTarget, 1, iByteSize)
End Function
Public Shared Function MidB(ByVal stTarget As String, ByVal iStart As Integer) As String
Dim hEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
Dim btBytes As Byte() = hEncoding.GetBytes(stTarget)
Return hEncoding.GetString(btBytes, iStart - 1, btBytes.Length - iStart + 1)
End Function
Public Shared Function MidB _
(ByVal stTarget As String, ByVal iStart As Integer, ByVal iByteSize As Integer) As String
Dim hEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
Dim btBytes As Byte() = hEncoding.GetBytes(stTarget)
Return hEncoding.GetString(btBytes, iStart - 1, iByteSize)
End Function
Public Shared Function RightB(ByVal stTarget As String, ByVal iByteSize As Integer) As String
Dim hEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
Dim btBytes As Byte() = hEncoding.GetBytes(stTarget)
Return hEncoding.GetString(btBytes, btBytes.Length - iByteSize, iByteSize)
End Function
End Class
Public Shared Function LeftB(ByVal stTarget As String, ByVal iByteSize As Integer) As String
Return MidB(stTarget, 1, iByteSize)
End Function
Public Shared Function MidB(ByVal stTarget As String, ByVal iStart As Integer) As String
Dim hEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
Dim btBytes As Byte() = hEncoding.GetBytes(stTarget)
Return hEncoding.GetString(btBytes, iStart - 1, btBytes.Length - iStart + 1)
End Function
Public Shared Function MidB _
(ByVal stTarget As String, ByVal iStart As Integer, ByVal iByteSize As Integer) As String
Dim hEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
Dim btBytes As Byte() = hEncoding.GetBytes(stTarget)
Return hEncoding.GetString(btBytes, iStart - 1, iByteSize)
End Function
Public Shared Function RightB(ByVal stTarget As String, ByVal iByteSize As Integer) As String
Dim hEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
Dim btBytes As Byte() = hEncoding.GetBytes(stTarget)
Return hEncoding.GetString(btBytes, btBytes.Length - iByteSize, iByteSize)
End Function
End Class
사용예
Dim stTarget As String = "ABCDEF"
MessageBox.Show(VBStrings.LeftB(stTarget, 6)) 'ABCD
MessageBox.Show(VBStrings.MidB(stTarget, 4)) 'CDEF
MessageBox.Show(VBStrings.MidB(stTarget, 4, 5)) 'CDE
MessageBox.Show(VBStrings.RightB(stTarget, 3)) 'EF
MessageBox.Show(VBStrings.LeftB(stTarget, 6)) 'ABCD
MessageBox.Show(VBStrings.MidB(stTarget, 4)) 'CDEF
MessageBox.Show(VBStrings.MidB(stTarget, 4, 5)) 'CDE
MessageBox.Show(VBStrings.RightB(stTarget, 3)) 'EF
3. LenB
선언
Public Class VBStrings
Public Shared Function LenB(ByVal stTarget As String) As Integer
Return System.Text.Encoding.GetEncoding("Shift_JIS").GetByteCount(stTarget)
End Function
End Class
Public Shared Function LenB(ByVal stTarget As String) As Integer
Return System.Text.Encoding.GetEncoding("Shift_JIS").GetByteCount(stTarget)
End Function
End Class
사용예
MessageBox.Show(VBStrings.LenB("あいうabc")) '9
'개발 > .Net' 카테고리의 다른 글
[VB.NET] ComboBox (0) | 2010.12.17 |
---|---|
[VB.NET] 픽쳐박스에 이미지파일을 표시후 바로 삭제하는 방법 (0) | 2010.12.17 |
[VB6→VB.NET] ListView (0) | 2010.12.16 |
[VB.NET] Form 명령어 (0) | 2010.12.16 |
[VB6→VB.NET] 배경색 변경 (0) | 2010.12.16 |
[VB6→VB.NET] TreeView (0) | 2010.12.16 |
[VB6] 엑셀파일 DB Import (0) | 2010.08.18 |
[VB6] 실행 파일의 하위에 존재하는 파일목록 얻어오기 (0) | 2010.08.18 |
[VB6] 리스트뷰(ListView)의 각 열의 배경색 변경하기 (0) | 2010.08.04 |
[VBA] 엑셀에서 MSSQL Server 접속하기 (0) | 2009.11.20 |