代币更换
我目前在页面渲染方法中实现了一个替换函数,该函数替换常用的字符串 - 例如将 [cfe] 替换为客户前端的根。这是因为根据站点版本的不同,该值可能会有所不同 - 例如,在开发和上线时,图像文件夹 ([imagepath])
的根目录是 /Images
,但是 /Test/Images
正在测试。
我有一个产品目录,我想将其 [productName]
更改为该产品目录页面的链接。我想浏览整个页面并将 [someValue]
的所有实例替换为相关链接。目前,我通过循环遍历产品数据库中的所有产品并将 [productName]
替换为该产品的目录页面的链接来实现此目的。然而,这仅限于数据库中存在的产品。当前已删除的产品的“链接”不会被替换,因此将向用户显示[someValue]
。这看起来不太好。
所以你应该能从这里看出我的问题。有谁知道有什么方法可以轻松实现我想要的目标?我可以使用正则表达式,但我对此没有太多经验。如果这是最简单的方法,使用“For Each Match As String In Regex.Matches(blah, blah)
”,那么我愿意进一步研究这一点。
然而,在某些时候,我想更进一步 - 例如使用 [layout type="3colImageTopRight" imageURL="imageURL"]Content here[/layout]< 设置页面布局,例如右上角带有图像的 3 列/代码>。我想我现在可以这样做,但是如果
imageURL
是,例如 [Image:Product01.gif]
(使用regex.match("[[a-zA-Z]{0,}]")
我认为只会匹配 [layout type="3colImageTopRight" imageURL="[Image:Product01. gif]
(它不会到达布局标记的末尾)。显然,上面的方法不太有效,因为我没有在匹配字符串或任何内容中包含双引号,但您已经了解了总体思路。 。您应该能够大致了解我正在做什么以及我正在尝试做什么。
如果这不是严格的令牌替换,那么请指出。我知道它是什么,这样我就可以进一步发展这一点
解释这一点可以解决困惑,
- 希望重新
谢谢,
理查德·克拉克。
I currently implement a replace function in the page render method which replaces commonly used strings - such as replace [cfe] with the root to the customer front end. This is because the value may be different based on the version of the site - for example the root to the image folder ([imagepath])
is /Images
on development and live, but /Test/Images
on test.
I have a catalogue of products for which I would like to change [productName]
to a link to the catalogue page for that product. I would like to go through the entire page and replace all instances of [someValue]
with the relevant link. Currently I do this by looping through all the products in the product database and replacing [productName]
with the link to the catalog page for that product. However this is limited to products which exist in the database. "Links" to products which have been removed currently wont be replaced, so [someValue]
will be displayed to the user. This does not look good.
So you should be able to see my problem from this. Does anyone know of a way to achieve what I would like to easily? I could use regexes, but I don't have much experience of those. If this is the easiest way, using "For Each Match As String In Regex.Matches(blah, blah)
" then I am willing to look further into this.
However at some point I would like to take this further - for example setting page layouts such as 3 columns with an image top right using [layout type="3colImageTopRight" imageURL="imageURL"]Content here[/layout]
. I think I could kind of do this now, but I cant figure out how to deal with this if the imageURL
were, say, [Image:Product01.gif]
(using regex.match("[[a-zA-Z]{0,}]")
I think would match just [layout type="3colImageTopRight" imageURL="[Image:Product01.gif]
(it would not get to the end of the layout tag). Obviously the above wouldn't quite work, as I haven't included double quotes in the match string or anything, but you get the general idea. You should be able to get the general idea of what I am getting at and what I am trying to do though.
Does anyone have any ideas or pointers which could help me with this? Also if this is not strictly token replacement then please point me to what it is, so I can further develop this.
Aristos - hope reexplaining this resolves the confusion.
Thanks in advance,
Regards,
Richard Clarke
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@RichardClarke - 我会选择正则表达式,它们并不像您想象的那么可怕,并且只要仔细使用就会解决您的问题。
我一直发现这是一个非常有用的工具。
与备忘单搭配得很好;-)
祝你好运。
@RichardClarke - I would go with Regular Expressions, they're not as terrible to learn as you might think and with a bit of careful usage will solve your problems.
I've always found this a very useful tool.
goes nicely with a cheat sheet ;-)
Good luck.