You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
471 B

3 weeks ago
  1. //判断是否为线上订单
  2. export const startsWith = (mainStr, prefix) => {
  3. // 处理前缀为空字符串的情况(空字符串是所有字符串的前缀)
  4. if (prefix === '') {
  5. return true;
  6. }
  7. // 处理主字符串长度小于前缀长度的情况
  8. if (mainStr.length < prefix.length) {
  9. return false;
  10. }
  11. // 比较主字符串开头与前缀相同长度的部分
  12. return mainStr.substring(0, prefix.length) === prefix;
  13. }