如何替换特定位置的字符串 [英] How to replace a string at a particular position

查看:497
本文介绍了如何替换特定位置的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在java脚本中替换给定位置的String的一部分。例如,我想在下面的字符串中使用 12 替换小时列中的 00 substring 是13到15。

Is there a way to replace a portion of a String at a given position in java script. For instance I want to replace 00 in the hours column with 12 in the below string.The substring comes at 13 to 15.

Mar 16, 2010 00:00 AM 


推荐答案

以下是一个选项:

var myString = "Mar 16, 2010 00:00 AM";

myString = myString.substring(0, 13) + 
           "12" + 
           myString.substring(15, myString.length);

请注意,如果您打算使用此操作日期,建议使用某个日期操作方法,例如 DateJS 中的操作方法。

Note that if you are going to use this to manipulate dates, it would be recommended to use some date manipulation methods instead, such as those in DateJS.

这篇关于如何替换特定位置的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆