Option Explicit
Function get_左手と右手の使用回数_str(argString)
Dim str_L, str_R, trgString, i, s, cnt_L, cnt_R
str_L = "qwertasdfgzxcvb"
str_R = "yuiophjklnm"
trgString = StrConv(argString, vbLowerCase + vbNarrow)
cnt_L = 0
cnt_R = 0
For i = 1 To Len(trgString)
s = Mid(trgString, i, 1)
If str_L Like "*" & s & "*" Then cnt_L = cnt_L + 1
If str_R Like "*" & s & "*" Then cnt_R = cnt_R + 1
Next
get_左手と右手の使用回数_str = cnt_L & "," & cnt_R
End Function
Function get_左手と右手の使用回数_arr(argString)
Dim arr_L, arr_R, trgString, i, s, cnt_L, cnt_R
arr_L = Split("q,w,e,r,t,a,s,d,f,g,z,x,c,v,b", ",")
arr_R = Split("y,u,i,o,p,h,j,k,l,n,m", ",")
trgString = StrConv(argString, vbLowerCase + vbNarrow)
cnt_L = 0
cnt_R = 0
For i = 1 To Len(trgString)
s = Mid(trgString, i, 1)
If UBound(Filter(arr_L, s)) > -1 Then cnt_L = cnt_L + 1
If UBound(Filter(arr_R, s)) > -1 Then cnt_R = cnt_R + 1
Next
get_左手と右手の使用回数_arr = cnt_L & "," & cnt_R
End Function
Function get_左手と右手の使用回数_dic(argString)
Dim dic_L, dic_R, trgString, i, s, cnt_L, cnt_R, e
Set dic_L = CreateObject("Scripting.Dictionary")
Set dic_R = CreateObject("Scripting.Dictionary")
For Each e In Split("q,w,e,r,t,a,s,d,f,g,z,x,c,v,b", ",")
dic_L.Add e, False
Next
For Each e In Split("y,u,i,o,p,h,j,k,l,n,m", ",")
dic_R.Add e, False
Next
trgString = StrConv(argString, vbLowerCase + vbNarrow)
cnt_L = 0
cnt_R = 0
For i = 1 To Len(trgString)
s = Mid(trgString, i, 1)
If dic_L.Exists(s) Then cnt_L = cnt_L + 1
If dic_R.Exists(s) Then cnt_R = cnt_R + 1
Next
get_左手と右手の使用回数_dic = cnt_L & "," & cnt_R
End Function
Sub Main()
Debug.Print get_左手と右手の使用回数_str("sample")
Debug.Print get_左手と右手の使用回数_str("baseball")
Debug.Print get_左手と右手の使用回数_str("PowerShell")
Debug.Print get_左手と右手の使用回数_str("Power Apps")
Debug.Print
Debug.Print get_左手と右手の使用回数_arr("sample")
Debug.Print get_左手と右手の使用回数_arr("baseball")
Debug.Print get_左手と右手の使用回数_arr("PowerShell")
Debug.Print get_左手と右手の使用回数_arr("Power Apps")
Debug.Print
Debug.Print get_左手と右手の使用回数_dic("sample")
Debug.Print get_左手と右手の使用回数_dic("baseball")
Debug.Print get_左手と右手の使用回数_dic("PowerShell")
Debug.Print get_左手と右手の使用回数_dic("Power Apps")
Debug.Print
End Sub