Send Text Messages in your application in C#

Sometimes, you want to do something that more than c# can do. In one of my projects, a deal bargain website requires to send out text messages to alert their members when pre-defined keywords match with the new deal submitted. It’s a great use of text messages alert to shopper who are looking for a particular keyword in the deal.

Continue reading “Send Text Messages in your application in C#”

Load Google Chart by Ajax using Asp.net MVC and jQuery

If you are looking for a modern chart tool in a modern browser, you must not not to know the free one that offer by Google – Google Chart, is a HTML5/SVG technology to provide cross-browser compatibility (including VML for older IE versions) and cross platform portability to iPhones, iPads and Android. No plugins are needed. Don’t get confused by the image chart offered by Google, which was another chart tool. Now the new HTML5 Google chart provides more interaction and better rendering to users .googlechartaspnetmvc Continue reading “Load Google Chart by Ajax using Asp.net MVC and jQuery”

How to check if string array contain a string

You don’t want to write a loop to detect if a string array contains a string and ends up searching the simplest way to do it without writing a loop over internet. This is what I found that’s most efficient for .net developers.

.Net 2.0

string[] strArray = { "Dell", "Acer", "HP" };
bool exist = Array.Exists(strArray , s=>s.ToLower().Contains("Asus"));

.Net 3.5

string[] strArray = { "Dell", "Acer", "HP" };
bool exist = strArray.Contains("Asus"));

How to strip/remove HTML in asp.net C#

Checking a user input contains html tag or not is not unfamiliar task to any web development project. Use the following strip html function in c#, you can take the html tag away from user inputs.

public static string StripHtml(string html, bool allowHarmlessTags)
{
      if (html == null || html == string.Empty)
           return string.Empty;

      if (allowHarmlessTags)
           return System.Text.RegularExpressions.Regex.Replace(html, "</?(?i:script|embed|object|frameset|frame|iframe|meta|link|style)(.|\n)*?>", string.Empty);

      return System.Text.RegularExpressions.Regex.Replace(html, "<[^>]*>", string.Empty);
}

Determine a string contains unicode Character in c#

If you need a function to determine different language such as Chinese/Japanese/French and so on. You may want to use the following function to determine if the input contains Unicode character.

Unicode strings use two bytes per character (or more), ANSI strings only one byte per character. ASCII only extends up to 127. 128..255 is commonly used for ANSI characters. Above that is only Unicode. Some characters from value 128 and above (including 128 itself) map to a unicode character with a value higher than 255 in codepage 1252.

public static bool IsUnicode(string input)
{
      const int MaxAnsiCode = 255;

      return input.ToCharArray().Any(c => c > MaxAnsiCode);
}