我有以下代码:
var specialchars = [246,214,228,196,252,220,223]; // holds german umlauts + ß
var foo = "abcdefä41hl";
检测foo是否包含数组中的字符ascii-code的最佳做法是什么?在这种情况下,它将返回true,因为它包含“ä”(ascii代码228)。
感谢
答案 0 :(得分:1)
您可以通过
检测到var specialchars = [246,214,228,196,252,220,223];
var foo = "abcdefä41hl";
var isExist = !!([...foo].find(itm => specialchars.includes(itm.charCodeAt())));
console.log(isExist); // true
或者您可以使用Array.prototype.some
代替find
,如评论
var isExist = [...foo].some(itm => specialchars.includes(itm.charCodeAt()));
答案 1 :(得分:0)
很容易:
Private Function GetValue2(path, file, startr, endr, startc, endc)
Dim wb As Workbook
Application.ScreenUpdating = False
Application.AskToUpdateLinks = False
Set wb = Workbooks.Open(path & Application.PathSeparator & file)
wb.Sheets(1).Activate
GetValue2 = Range(Cells(startr, startc), Cells(endr, endc))
wb.Close (False)
Application.AskToUpdateLinks = True
Application.ScreenUpdating = True
End Function
它将字符串拆分为字符数组,仅保留特殊字符列表中存在的字符,并检查是否有任何字符。