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的更多相关文章

  1. VFP自定义函数StringFormat (仿.NET String.Format 方法)

    VFP仿.NET String.Format 方法 将指定字符串中的每个{x}替换为相应值,并返回文本 *-- 调用格式 StringFormat("日期{2},字符{1}",&q ...

  2. JS字符串格式化函数 string.format

    原生JS写的仿C#的字符串format函数,在此基础上又增加了便于JS使用的字面量对象参数. 参照C#中的规则,调用的时候会检测字符串格式,如果字符串格式不规范,或者传入的参数为null或undefi ...

  3. c# 字符串连接使用“+”和string.format格式化两种方式

    参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...

  4. 【转】string.Format对C#字符串格式化

    转自:http://blog.csdn.net/samsone/article/details/7556781 1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) str ...

  5. C#中string.format用法详解

    C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...

  6. string.Format格式化用法详解

    1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...

  7. Js实现string.format

    经常需要动态拼接html字符串,想到用类似于.net的string.format函数比较好,于是找了下,stackoverflow的代码: if (!String.prototype.format) ...

  8. String.Format用法

    http://blog.csdn.net/yohop/article/details/2534907 1.作为参数   名称 说明   Format(String, Object) 将指定的 Stri ...

  9. String.Format 格式说明

    C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...

随机推荐

  1. C#对屏幕分辨率的操作

    winform应用程序 1.新建Resolution.cs类 using System; using System.ComponentModel; using System.Windows.Forms ...

  2. android.support.v4.app.NotificationCompat引用包

    在导入使用了ViewPage,ActionBar,Fragment的工程后出现错误,很有可能是没有导入4.0版本的支持包.本人也是碰到这个问题,特意搜索了一下,得到解决办法如下,记录下来,以免忘记.  ...

  3. git push 本地项目推送到远程分支

    大家有的时候,会在本地新建项目,这里说一下在本地项目建立本地git仓库,然后push到远程仓库的步骤 1.在本地项目的文件夹下,git仓库初始化 git init 初始化本地git仓库 2. git ...

  4. C#实现json压缩和格式化

    json作为常用数据文件,为了传输的效率,在传输前要进行压缩,而在传输后要进行格式化,以便阅读.下面是使用C#完成的格式化和压缩代码. public static string Compress(st ...

  5. cesium 拾取模型表面的坐标

    scene = viewer.scene;var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);handler.setInput ...

  6. python函数与模块(装饰器,文件处理,迭代器等)

    os模块 os.system('命令') 利用python调用系统命令,命令可以是以列表或者元组内的元素形式* res import os res=os.system('ipconfig') prin ...

  7. NodeJS-静态服务器

    静态服务器 代码 const http = require('http') const chalk = require('chalk') const conf = require('./config/ ...

  8. 如何将composer设置为全局变量?

    全局安装是将 Composer 安装到系统环境变量 PATH 所包含的路径下面,然后就能够在命令行窗口中直接执行 composer 命令了. Mac 或 Linux 系统: 打开命令行窗口并执行如下命 ...

  9. python-pytest学习

    一:pytest基于unittest之上的单元测试框架1.自动发现测试模块和测试方法:2.断言使用assert+表达式即可:3.可以设置会话级.模块级.类级.函数级的fixtures :数据准备+清理 ...

  10. Python paramiko模块基本使用(一)

    使用paramiko模块登录远程主机,对日志进行统计分析. import paramiko def batch_count(days, hours, ips, user, passwd, source ...