English 中文(简体)
• 如何将可变名称改为可变值
原标题:How To Replace Variable Name To Variable Value In Swift?
  • 时间:2023-09-17 02:28:27
  •  标签:
  • swift
  • regex

I want to replace variable name between {{}} to its value, just like: I can using Dictionary like:

//var a = 10
//var b = 20
var pairs:[string:int]=["a":10,"b":20]
var str = "I have {{a}} apples and {{b}} pears"

And Target is "I have 10 apples and 20 pears" How Can I Do It In Swift Using Regex?

问题回答

正如Alexander指出的,如果你重新试图采取从方案外读到的任意强权,并且根据方案内部的变数采用替代法,那么这种替代就在迅速不可能。 你们需要以不同方式储存数据(如假冒)。 图书馆如GRMustache 这表明可以做到这一点,并具体处理你重新描述的那种辛迪加。

However, if this String is known at compile-time, you can apply string interpolation to it:

var str = "I have (a) apples and (b) pears"

这纯粹是一个汇编时代的特点。 你们不能像现在这样阅读一种扼制格式,并且出现替代物。 这将使数据能够查阅该守则,而该守则基本上不允许迅速查阅。





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签