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

php - multilevel menu with multilevel array -

c# - TypeConverter in propertygrid only converts from string, not to -

jQuery UI: Datepicker month format -