Javascript equivalent to C strncmp (compare string for length) -


What is the equivalent function in javascript in strncmp? Strncmp takes two string arguments and an integer length argument. It will be comparable to the length of two strings and determines the length of the distance as far as it was.

Is there a built-in function in Javascript equivalent?

You can easily create this function:

  function strncmp (Str1, str2, n) {str1 = str1.substring (0, n); Str2 = str2.substring (0, n); Return (str1 == str2)? 0: ((str1> str2)? 1: -1)); }  

At the end of the function can be an option for Ternary, such as return str1.localeCompare (str2);


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -