[Solved] Jquery – Find a word in a string and wrap it with tag

You need to do this : var txt = textDiv.replace(new RegExp(searchInput, ‘gi’), function(str) { return “<span class=”highlight”>” + str + “</span>” }); or var txt = textDiv.replace( new RegExp(searchInput, ‘gi’), “<span class=”highlight”>$&</span>”); gi -> all case insensitive matching text $(document).ready(function() { // globals var searchInput; var textDiv; $(‘.searchBtn’).click(function(event) { event.preventDefault(); // set the values of … Read more

[Solved] Find index of returned list result C#

As the error states, it cannot convert from ‘System.Collections.Generic.List’ to ‘string’. However I never knew the function SingleOrDefult() existed. All credit to @maccettura even though he didn’t know what I was trying to do! xD Code change below for the answer: List<string> listFrom = new List<string>(); //Contains a list of strings List<string> listTo = new … Read more

[Solved] JavaScript taking information from a email address

First get the email address to parse. You’ve already done that. Here, x contains the email address. var x = document.getElementById(“myText”).value; Now you can use x.indexOf(“.”) to get the position of the first period. Likewise, use x.indexOf(“@”) to get the position of the “@” symbol. These two values are passed to x.substring() to get the … Read more

[Solved] JavaScript IndexOf with heterogeneous array [closed]

Why 5 is missing ? console.log(5 === “5”) indexOf(5) isn’t -1 because 5 and “5” are two different value ( indexOf uses strict equality ) MDN indexOf console.log([5].indexOf(5)) console.log([“5”].indexOf(5)) How can i match both 5 or “5” ? Check for both numeric and string value. var myArray = [“2”, “3”, 5] var found = []; … Read more

[Solved] Index and length must refer to a location within the string ASP.NET [duplicate]

I think you are looking for String.Insert Returns a new string in which a specified string is inserted at a specified index position in this instance. So simply use return name.Insert(extPos, “_180x140”); However as per your error is concerned use return name.Substring(0, extPos) + “_180x140” + name.Substring(extPos); solved Index and length must refer to a … Read more

[Solved] String.indexOf gives a value one less than expected

Indexes are zero-based: ↓ Peter Piper picked a peck of pickled pepper 111111111122222222223333333333444 0123456789012345678901234567890123456789012 ↑ The first p is at index 8. From the javadoc of indexOf(): Returns the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur. solved String.indexOf … Read more