0

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!

2 Answers 2

2
var audience = "Nderon Hyseni John Champion Martin Tyler";
var _username = user.get_title(); //Nderon Hyseni
if(audience.Contains(_username)){
   //found
} else {
   //not found
}

I haven't wrote in c# for months, but it should work.

EDIT Whoooa... javascript ;D

var audience = "Nderon Hyseni John Champion Martin Tyler";
var _username = user.get_title(); //Nderon Hyseni
if(audience.indexOf(_username) > -1){
   //found
} else {
   //not found
} 

This should work :)

Sign up to request clarification or add additional context in comments.

5 Comments

I am note sure if this works also in JavaScript becaus my solution is in javascript
thanks i will try this tomorrow in my office but could you explain me why is that -1 for?
but I think that this funcion .indexOf return the position of number
Sorry for such late response. Yeah indexOf does exactly what you said, and that's why there is -1. It means that _username is not present in audience. In this example it would return 0, because audience begins with string stored in _username. :)
anyway brother thanks for your time you took to watch my question.
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.