如何生成具有 X 标记和每个标记的 Y 值的字符串的所有可能性
所以,我有一个模板字符串,其中包含 X 数量的令牌。假设它可能看起来像这样:
template = "render=@layer0@-@layer1@-@layer2@-@layer3@-@layer4@"
显然,令牌采用 @tokenname@
的形式。在这个假设的情况下,它有五个令牌。每个令牌都有一组不同的可能值。例如:
token0Values = ['t0value1'];
token1Values = ['t1value1','t1value2'];
token2Values = ['t2value1','t2value2','t2value3'];
token3Values = ['t3value1','t3value2'];
token4Values = ['t4value1','t4value2','t4value3','t4value4'];
我的问题是,在给定模板和每个标记的可能值的情况下,如何生成字符串的每种可能的排列?
So, I have a template string with X amount of tokens in it. Hypothetically it could look like this:
template = "render=@layer0@-@layer1@-@layer2@-@layer3@-@layer4@"
The tokens, obviously, take the form of @tokenname@
. In this hypothetical case it has five tokens. Each token has a different set of possible values. For example:
token0Values = ['t0value1'];
token1Values = ['t1value1','t1value2'];
token2Values = ['t2value1','t2value2','t2value3'];
token3Values = ['t3value1','t3value2'];
token4Values = ['t4value1','t4value2','t4value3','t4value4'];
My question then is, how do I generate every possible permutation of the string given the template and the possible values for each token?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将尝试一下 php/AS
令牌是可能值的二维数组
{
[0] =“苹果”、“香蕉”、“梨”
[1] =“胡萝卜”,“豌豆”
[2] =“土豆”、“芹菜”、“黄油”、“肉汁”
这
可能有效,或者类似的东西
I'll take a stab at it in sorta php/AS
tokens is a two dimensional array of possible values
{
[0] = "apple","banana","pear"
[1] = "carrot","pea"
[2] = "potato", "celery", "butter","gravy"
}
that might work, or something similar