C# shorten link c# - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution
join us

shorten link using C#


 746

Show ResultC#


1

<%@ Page Language="C#" AutoEventWireup="true"%>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{

string MyText = "some text https://net-raft.com/Questions/1311/how-to-detect-the-type-of-a-browser-using-c-in-aspnet-/1311 some text";
string Newstring = "";
char[] delimiterChars = { ' ' };
string[] words = MyText.Split(delimiterChars);

foreach (string word in words)
{
bool isValid = Regex.IsMatch(word,@"^(http|ftp|https|www)://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?$");
if(isValid)
{

Uri myUri = new Uri(word);
string Scheme_Host = myUri.GetLeftPart(System.UriPartial.Authority);
String parentDirectory = myUri.AbsolutePath;
string Myurl;
int chars_url = parentDirectory.Length;

if (chars_url > 62) {

string str1 = parentDirectory.Substring(0,22);
string str2 = parentDirectory.Substring(chars_url - 11, 11);

Myurl = Scheme_Host + str1 + "..." + str2;
Newstring = Newstring + " " + "<" + "a href=" + word + " target=_blank>" + Myurl + "<a>";

}

else

{
Newstring = Newstring + " " + "<" + "a href=" + word + " target=_blank>" + word + "<a>";
}

}
else
{

Newstring = Newstring + " " + word;

}

}

lbltxt.InnerHtml = Newstring;

}
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<form id="form1" runat="server">
<div>
<label id="lbltxt" runat="server"></label>
</div>
</form>
</body>
</html>


By        
The power of the user (%)
15%



The most helpful C# solutions

detect ie C#detect ie C#C#

Click to see more ...

  4.6K     853

get latitude and longitude from ip address c#get latitude and longitude from ip address c#C#

Click to see more ...

  2.8K     257

get real user country C#get real user country C#C#

Click to see more ...

  1.7K     252

Get real client ip address using C# ?Get real client ip address using C# ?C#

Click to see more ...

  1.8K     247

check if cookie exists c#check if cookie exists c#C#

Click to see more ...

  6.3K     173

get city country region timezone c#get city country region timezone c#C#

Click to see more ...

  2.7K     163

How to detect the browser opera using C# in asp.net ?How to detect the browser opera using C# in asp.net ?C#

Click to see more ...

  2.3K     136

get hostname using C#get hostname using C#C#

Click to see more ...

  1.1K     127

Get real client latitude and longitude using C# ?Get real client latitude and longitude using C# ?C#

Click to see more ...

  829     127

how to initialize a connection to mysql database using C# ?how to initialize a connection to mysql database using C# ?C#

Click to see more ...

  1.2K     122

Welcome aboard!
We are happy you are here and
wish you good net-raft!