Vue仿string.format
Vue.prototype.$stringFormat = function stringFormat (formatted, args) {
for (let i = 0; i < args.length; i++) {
let regexp = new RegExp('\\{' + i + '\\}', 'gi')
formatted = formatted.replace(regexp, args[i])
}
return formatted
}
仿照string.format("{0}-{1}","你好", "世界")
使用方法:
$stringFormat("{0}-{1}",["你好", "世界"])
Vue仿string.format的更多相关文章
- VFP自定义函数StringFormat (仿.NET String.Format 方法)
VFP仿.NET String.Format 方法 将指定字符串中的每个{x}替换为相应值,并返回文本 *-- 调用格式 StringFormat("日期{2},字符{1}",&q ...
- JS字符串格式化函数 string.format
原生JS写的仿C#的字符串format函数,在此基础上又增加了便于JS使用的字面量对象参数. 参照C#中的规则,调用的时候会检测字符串格式,如果字符串格式不规范,或者传入的参数为null或undefi ...
- c# 字符串连接使用“+”和string.format格式化两种方式
参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...
- 【转】string.Format对C#字符串格式化
转自:http://blog.csdn.net/samsone/article/details/7556781 1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) str ...
- C#中string.format用法详解
C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...
- string.Format格式化用法详解
1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...
- Js实现string.format
经常需要动态拼接html字符串,想到用类似于.net的string.format函数比较好,于是找了下,stackoverflow的代码: if (!String.prototype.format) ...
- String.Format用法
http://blog.csdn.net/yohop/article/details/2534907 1.作为参数 名称 说明 Format(String, Object) 将指定的 Stri ...
- String.Format 格式说明
C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...
随机推荐
- 三个线程,ABC 10次(volatile+synchronized)
package ThreadABC; public class Share { private volatile int status; public int getStatus() { return ...
- Cesium学习网址
不错的案例介绍: 根据地形瓦片直接绘制高程.坡度及等高线 同一场景下显示两个不同的瓦片图层 https://cloud.tencent.com/developer/article/1113355 绘制 ...
- python类特列方法使用
class Rgc(object): def __new__(cls, *args, **kwargs): print('在类通过__new__方法实例化一个对象') return super(Rgc ...
- qt qextserialport __imp_SetupDiGetDeviceRegistryPropertyW
使用 qextserialport 编写串口助手的时候,提示找不到 __imp_SetupDiGetDeviceRegistryPropertyW,经过摸索有以下两种解决方法: 第一种: 把相应的源文 ...
- LeetCode 206. Reverse Linked List倒置链表 C++
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...
- TCP协议-连接建立和释放
三次握手: (1)客户端向服务器端TCP请求连接,向服务器端发送控制位SYN=1,序号seq=x的请求报文.(x是随机产生的,且不能为0) (2)服务器端接收到请求报文后,若同意建立连接,则向客户端发 ...
- 监控linux服务器是否能登陆 邮件报警
import smtplibfrom email.mime.text import MIMETextimport telnetlibimport timedef SendEmail(fromAdd,t ...
- django之关联field 描述子
"""Accessors for related objects. When a field defines a relation between two models, ...
- JAVA的第二次作业
1.编写“人”类及其测试类.1.1 “人”类: 类名:Person 属性:姓名.性别.年龄.身份证号码 方法:在控制台输出各个信息1.2 测试类 类名:TestPerson 方法:main ...
- linux程序一般设置
看canal的时候看了下deploy的脚本,发现很多系统都大同小异 如果是需要debug,就需要开启调试端口 if [ "$1" = "debug" ]; th ...