I have a question about substring-after and substring-before that I'm used to use in XSLT, but now I have to use the same feature in Razor in Umbraco 7.
The second check in the videoId-variable is used to make sure that there's not any extra parameters in the URL. Something like a URL looking like this:
substring-after and substring-before in Razor?
Hi all
I have a question about substring-after and substring-before that I'm used to use in XSLT, but now I have to use the same feature in Razor in Umbraco 7.
Let's say I have a link from YouTube that looks like this:
https://www.youtube.com/watch?v=tF03jgCgV7s
If I just want to grab the ID of the video (the parts that comes after the ?v=) in that string I would do something like this in XSLT:
The second check in the videoId-variable is used to make sure that there's not any extra parameters in the URL. Something like a URL looking like this:
https://www.youtube.com/watch?v=tF03jgCgV7s&featured=true
How can I achieve the same as above in Razor?
Thanks in advance.
/Kim A
Hi Kim
I don't think there is such same thing in Razor - But perhaps http://www.dotnetperls.com/substring can help a bit? Otherwise the way forward may be using regex like Warren shows an example of in this rather old thread? http://our.umbraco.org/forum/developers/razor/26473-substring-before-substring-after
Some of the backend guys'n'gals at the office must have an idea about it otherwise then I think since it's just c#, right? :)
You can probably also look into using "indexOf" in combination with substring.
Hope this helps.
/Jan
Hi Kim :-)
Try to see JeavonĀ“s suggestion here maybe you could use the same approach http://our.umbraco.org/forum/developers/razor/56828-Extract-Youtube-ID-from-url
Hope this helps,
/Dennis
Hi Kim :-)
Or maybe you can get some inspiration from this post here http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/54749-Youtube-Embed
/Dennis
Hi guys
I used the trick from the post Dennis linked to, where Jeavon had a great answer. It solved my issue in this case.
If anyone else is interested in the answer in this case, the following code (more or less copied from the other thread) solved it for me:
Thanks!
/Kim A
is working on a reply...