How to split multi character in MVC3? - asp.net-mvc-3

Hello everyone I'm trying to remove some characters in my text box
For example
In my textbox, user fill with this text as you can see at below
http://youtu.be/YBkPomr40pg
I want to remove these characters http://youtu.be/
So how can I do could you show me an example ?

Load the URL into a Uri and get the relative URL from it. http://msdn.microsoft.com/en-us/library/system.uri.aspx
See this question for how to get the relative URL: Getting the relative uri from the absolute uri
Note that you will get the URL with the starting /. You can trim that yoruself.
If you're saying that you are ONLY going to be getting youtube URLs and you want simply the youtube video ID, this same technique can work, but you mgiht be better off just using string split to split on '/' and getting the last item.
var parts = "http://youtu.be/YBkPomr40pg".Split("/".ToCharArray());
var id = parts[parts.Length - 1]; // just get the last one.

Related

String interpolation does not work with some url

I don't know how to replicate the problem here... I let you see the problem I have:
I must build an url and I am using string interpolation:
var url = $"{_baseAddress}/api​/freightcategories/​{categoryCode}";
Here the result:
As you can see last part of the url is white.... and if I call that url via HttpClient I get a 404 error...
I replaced the line above with this line:
var url = string.Format("{0}/api​/freightcategories/{1}", _baseAddress, categoryCode);
I get this:
Now if I call the url via HttpClient everything works correctly.
Any idea?
Thank you
Bas Paap reply on url in interpolated string breaks syntax coloring:
When using an interpolated string that contains an url followed by an
interpolated value, the syntax highlighting thinks the interpolated
value is part of the url and formats it as a link, up to and including
the first parameter.
I guess the url is analyzed this way: When an http or https sequence is encountered at the beginning of a string, the process of building the url starts, and values are appended to url until there is something unknown, like an interpolated value.
According to your case, _baseAddress might be interpolated first, which results in url having the following value: https://yoururl.whatever/api/freightcategories/​, which is a valid url and it is formatted properly, and I guess here the formatting stops because the next value is an interpolated one, which is unknown at the moment (_baseAddress value is know, but categoryCode not yet), so it stops the formatting and when categoryCode is appended, is simply does not care about formatting the url further. (This is how I think it works and it makes sense).
Here is a quick solution to build an url using string interpolation:
var url = "h" + $"{_baseAddress.Substring(1)}/api​/freightcategories/​{categoryCode}";
When h will meet ttps://yoururl.whatever/api...., the https is encountered at the beginning and the formatting starts. _baseAddress and categoryCode values are already a part of second string.
It is their issue and, as far as I know, Microsoft didn't solve it yet.
Also, you can try to specify an Uri instance rather that a string when sending a request, something like
var uri = new Uri($"{_baseAddress}/api​/freightcategories/​{categoryCode}");
client.GetAsync(uri);

visit a Full URL with parameter value

I'm trying to make a bash script to send a GET requests
also I'm trying to provide a URL access after changing some parameter value
problem:
when I hover over the link it will only underline URL without parameters values(check the following screen)
when I entered the URL it will redirect me to:
http://testphp.vulnweb.com/artists.php?artist=
I'm wondering if there is a solution for this case or not
Thank you in advance
Note that it's the terminal and not your script that decides what's considered part of a URL for the purpose of selecting or clicking.
But what I can suggest is to Use the URL encoding for those special characters instead of explicit special characters:
%27 = Single Quote **'**
%3C = Less than **<**
%3E = More than **>**
For example
URL=http://testphp.vulnweb.com/artists.php?artist=
PARTIAL_URL=$URL%3Cscript%3E
That will be shown http://testphp.vulnweb.com/artists.php?artist=<script>
Maybe that would do the trick

Using url unescape to build a url within a view in a string

I am building a url in a view within my sinatra app
I required the URI module in my app.
<li>Show</li>
Without URI.unescape I do not see %20 when I hover over the link. I just see this:
http://127.0.0.1:9292/blog/Coffee Title/49459
I am hoping for that space to be a -. But when I click on the link it will return in my browser as:
http://127.0.0.1:9292/blog/Coffee%20Title/49459
I tried using URI.unescape in irb. I am having trouble evaluating the Ruby code within the string. I am not sure what the right format is but think I am getting close.
URI.escape replaces characters in a string with their percent-encoded counterpart, which is why a space character becomes %20 (20 is the ASCII character code for space). It does not replace spaces with dashes.
To replace a character with another character in a string, use String#tr:
title = "Coffee Title"
title_with_dashes = title.tr(" ", "-")
puts title_with_dashes
# => Coffee-Title
However, this is only half of the equation. You've changed the URLs in your links but as a consequence your server probably isn't going to recognize the URL when someone clicks on the link, because the path that exists is Coffee Title, not Coffee-Title. That's a topic for another question, though.

Get Pinterest RSS feed for board with special characters

Normally, to get the RSS feed for a Pinterest board, you simply add ".rss" to the end of the URL.
For example, for the board at http://www.pinterest.com/philchairez/mega-man-x/, you can get the RSS feed from http://www.pinterest.com/philchairez/mega-man-x.rss.
If a board has a special character in its name, usually, it seems like Pinterest has simply removed the special characters from the assigned URL.
For example, this board is named "film + music + books + games" and its URL is http://www.pinterest.com/claramechelle/film-music-books-games/ (notice that the '+' characters are excluded).
Another example: "Kids diy games + musical instruments", http://www.pinterest.com/sammijjohno/kids-diy-games-musical-instruments/
Getting the RSS feeds for these boards works as expected:
http://www.pinterest.com/claramechelle/film-music-books-games.rss
http://www.pinterest.com/sammijjohno/kids-diy-games-musical-instruments.rss
However, URLs for some boards sometimes include the URL encoding of a special character. For example, this board is named "Dungeons + Dragons":
http://www.pinterest.com/lizardskingirl/dungeons-%2B-dragons/
And this board is named "Game Art + UI/HUD":
http://www.pinterest.com/portableneko/game-art-%2B-uihud/
Adding ".rss" to these URLs does not work:
http://www.pinterest.com/lizardskingirl/dungeons-%2B-dragons.rss
http://www.pinterest.com/portableneko/game-art-%2B-uihud.rss
You'll just get redirected to the user's board list. If you try to simply remove the special character like the other URLs, you'll get a 404.
Does anyone know how to get the RSS feed for boards like this?
Try this
http://pinterest.com/[username]/feed.rss
For example, my username is "sharp", so my RSS feed can be found at:
http://pinterest.com/sharp/feed.rss
Source:
http://www.quora.com/Does-Pinterest-have-plans-to-allow-for-RSS-feeds-for-a-users-specific-pinboards
You can get the rss feed if you replace the character encoding with the actual '+', and then tack '.rss' to the end:
http://www.pinterest.com/portableneko/game-art-%2B-uihud becomes:
http://www.pinterest.com/portableneko/game-art-+-uihud.rss
Renaming a board doesn't change its internal name, so if you have renamed a board see if you can remember its original name and generate the .rss URL from that.

How to get the last word from a URL?

Is there a method to extract just the last word from the URL example below? I would like to be able to use this as a heading on a page, i.e the "Account" page.
I found that by using request.path it will give me the path without the root but I'm not sure how to get just the last path name.
/users/1234/account
Try:
request.path.split('/').last
If you want "Account" (instead of "account"), call the capitalize method on the result.
I am not familiar with Ruby, but you can try this approach.
Try string splitting request.path with '/' as the separator and take the last element from the resulting array
users/1234/account will be split to {'user', '1234', 'account'}
Even though this doesn't answer your question directly, I hope it gives you a start
URLs are a simple string consisting of a scheme showing how to connect to a site, the host where the resource is located, plus a path to that resource. You can use File.basename to get the last part of that path, just like we'd use on a file on our disk:
File.basename('/users/1234/account')
=> "account"
Suppose you have URL like https://www.google.com/user/lastword
If you want to store last word of the URL which is lastword in a variable then use the following and pass url as value to finalVal.
var getLastWordFromUrl = finalVal.split("/").last()

Resources