Nderon Hyseni Nderon Hyseni - 5 months ago 21
Javascript Question

How to find a substring inside a string via JavaScript in SharePoint?

i have the following solution:

var audience = "Nderon Hyseni John Champion Martin Tyler";


var _username = user.get_title(); //This variable show the user that is currently logged in


Example:

I am logged in with a user which name is Nderon Hyseni, how can i say if _username (this username Nderon Hyseni is currently logged in) value is in
audience
variable
alert("Pass")
if not
alert(failed)


thanks all!

Answer

This is what i was looking for, but anyway thanks

var str = "NderonHyseniBurimRamusaAlenScott"; 
var test = "NderonHyseni";//username

var res = str.match(test);
document.getElementById("demo").innerHTML = res;

if(res != null)    
    alert("true");

else
   alert("false");}
Comments