Skip to content

Instantly share code, notes, and snippets.

@SeongilRyu
Last active January 9, 2019 06:17
Show Gist options
  • Save SeongilRyu/f5310e5b7713572ea294e6e36a2bc6cc to your computer and use it in GitHub Desktop.
Save SeongilRyu/f5310e5b7713572ea294e6e36a2bc6cc to your computer and use it in GitHub Desktop.
Functions of String
Sub show_strings()
Dim str As String
str = "Microsoft VBA"
''1. InStr: 문자가 나타난 첫번째 위치
Debug.Print InStr(str, "VBA") ''Result= 11
''2. InStrRev: 역순으로 문자가 나타난 첫번째 위치
Debug.Print InStrRev(str, "VBA") ''Result= 11
''3. LCase: 소문자로 변경
Debug.Print LCase(str) ''Result= microsoft vba
''4. UCase: 대문자로 변경
Debug.Print UCase(str) ''Result= MICROSOFT VBA
''
''5. Left: 왼쪽부터 주어진 숫자만큰 문자를 자르기
Debug.Print Left(str, 5) ''Result= Micro
''6. Right: 오른쪽부터 주어진 숫자만큰 문자를 자르기
Debug.Print Right(str, 5) ''Result= t VBA
''7. Mid: 6자리부터 7문자 자르기
Debug.Print Mid(str, 6, 7) ''Result= soft VB
''
''8. LTrim: 왼쪽의 공백 제거
Debug.Print LTrim(str) ''Result= Microsoft VBA
''9. RTrim: 오른쪽의 공백 제거
Debug.Print RTrim(str) ''Result= Microsoft VBA
''10. Trim: 공백 제거
Debug.Print Trim(str) ''Result= Microsoft VBA
''
''11. Len: 문자열의 길이
Debug.Print Len(str) ''Result= 13
''12. Replace: 문자열의 치환
Debug.Print Replace(str, "Microsoft", "Google") ''Result= Google VBA
''13. Space: 공백 삽입
Debug.Print str & Space(10) & "Tutorial" ''Result= Microsoft VBA Tutorial
''
''14. StrComp: 문자열 비교
Debug.Print StrComp(str, "Google VBA") ''Result= 1
''15. String: 주어진 문자열 삽입
Debug.Print String(3, "$") ''Result= $$$
''16. StrReverse: 역순으로 문자열 표시
Debug.Print StrReverse(str) ''Result= ABV tfosorciM
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment