You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaScript实现地址字符串中Ap后续字符全大写的处理方案

地址指定部分转大写的实现方案

你的代码问题在于只截取了Ap之后的内容,没有保留前面的部分,也没对目标部分做大写转换。正确的思路是找到Ap的位置,把该位置及之后的内容转大写,再和前面的内容拼接。

修正后的代码

NewAddress = toggleCaseText(GetRecordsLF_Address); // 原地址:3513 Jones Drive Apt #500a
const apIndex = NewAddress.indexOf('Ap');
if (apIndex !== -1) {
  // 截取Ap之前的部分 + Ap及之后的部分转大写
  FinalAddress = NewAddress.substring(0, apIndex) + NewAddress.substring(apIndex).toUpperCase();
} else {
  // 没找到Ap的情况,直接用原地址
  FinalAddress = NewAddress;
}

代码说明

  • 先用indexOf('Ap')找到目标片段的起始位置apIndex
  • 判断索引是否有效(避免地址中没有Ap的异常情况)
  • 用substring(0, apIndex)获取Ap之前的原始内容
  • 用substring(apIndex).toUpperCase()把Ap及之后的所有内容转大写
  • 拼接两部分得到最终目标地址:3513 Jones Drive APT #500A

内容的提问来源于stack exchange,提问作者Codestarwik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 21:10:28