Skip to content

Instantly share code, notes, and snippets.

@furyutei
Last active November 6, 2020 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furyutei/8bdb5d9f065792a959ea7da6f762a424 to your computer and use it in GitHub Desktop.
Save furyutei/8bdb5d9f065792a959ea7da6f762a424 to your computer and use it in GitHub Desktop.
[Excel]サロゲートペア対応が不完全……なんとかしてください、エクセルさん!😅
Option Explicit
Function StringToArray(source_string)
Dim matches, match_part, position, result
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "[\ud800-\udbff][\udc00-\udfff]|[^\ud800-\udfff]"
Set matches = .Execute(source_string)
If matches.Count < 1 Then
StringToArray = Array()
Exit Function
End If
ReDim result(1 To matches.Count)
position = 0
For Each match_part In matches
position = position + 1
result(position) = match_part
Next
End With
StringToArray = result
End Function
=COUNT(UNICODE(MID(A1,SEQUENCE(LEN(A1)),1)))
=LET(対象文字列,A1,COUNT(UNICODE(MID(対象文字列,SEQUENCE(LEN(対象文字列)),1))))
=SUBSTITUTE(
MID(
CONCAT(
IF(
ISERROR(UNICODE(MID(A1,SEQUENCE(LEN(A1)),1))),
MID(A1,SEQUENCE(LEN(A1)),2),
IF(
ISERROR(UNICODE(MID(0&A1,SEQUENCE(LEN(A1)),1))),
"",
MID(A1,SEQUENCE(LEN(A1)),1)&CHAR(26)
)
)
),
SEQUENCE(,COUNT(UNICODE(MID(A1,SEQUENCE(LEN(A1)),1))),,2),
2
),
CHAR(26),
""
)
=LET(
対象文字列, A1,
置換用文字, CHAR(26),
文字の位置, SEQUENCE(LEN(対象文字列)),
文字配列, MID(対象文字列,文字の位置,1),
文字コード配列, UNICODE(文字配列),
ひとつ前の文字コード, UNICODE(MID(置換用文字&対象文字列,文字の位置,1)),
SUBSTITUTE(
MID(
CONCAT(
IF(
ISERROR(文字コード配列),
MID(対象文字列,文字の位置,2),
IF(
ISERROR(ひとつ前の文字コード),
"",
文字配列&置換用文字
)
)
),
SEQUENCE(,COUNT(文字コード配列),,2),
2
),
置換用文字,
""
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment