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 check if enter key pressed in jquery

In a user specific designed application or website, we want application start taking action without user click extra button. Especially in the scenario of search function. You want user be able to start searching when enter key is pressed on the textbox.

<input type="text" id="search" />
<script>
$('#search').keypress(function(e) {
    var keyCode = (e.keyCode ? e.keyCode : e.which);
    if(keyCode  == 13) {
        alert('Enter key pressed');
    }
});
</script>

How to check if enter key pressed in javascript

In a user specific designed application or website, we want application start taking action without user click extra button. Especially in the scenario of search function. You want user be able to start searching when enter key is pressed on the textbox.

function checkEnter(e){
var keyCode = (e.keyCode ? e.keyCode : e.which);
if(keyCode == 13){
//perform action
alert(‘enter key pressed’)
}
}

[html]
<input type="text" onkeypress="checkEnter(event);" />
[/html]
[javascript]
<script>
function checkEnter(e){
var keyCode = (e.keyCode ? e.keyCode : e.which);
if(keyCode == 13){
//perform action
alert(‘enter key pressed’)
}
}
</script>
[/javascript]]

Click here to see the jquery version

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, &quot;&lt;/?(?i:script|embed|object|frameset|frame|iframe|meta|link|style)(.|\n)*?&gt;&quot;, string.Empty);

      return System.Text.RegularExpressions.Regex.Replace(html, &quot;&lt;[^&gt;]*&gt;&quot;, string.Empty);
}