Oct 18, 2001 #1 Giddygoat Programmer May 16, 2001 36 GB I am wondering if there is a function that returns the number of times a character appears in a string. i.e. x = UnknownFunction('do da do da', 'd'); would result in x = 4 Cna anyone help...please John
I am wondering if there is a function that returns the number of times a character appears in a string. i.e. x = UnknownFunction('do da do da', 'd'); would result in x = 4 Cna anyone help...please John
Oct 18, 2001 Thread starter #2 Giddygoat Programmer May 16, 2001 36 GB I had some help here and we came up with this. I there is a more elegant solution please let me know. function CountChar(myString, char) { done = false; count = 0; pos = -1; while (!done) { pos++; pos = myString.indexOf(char, pos); if (pos == -1) { done = true; } else { done = false; count++; } } return count; } Upvote 0 Downvote
I had some help here and we came up with this. I there is a more elegant solution please let me know. function CountChar(myString, char) { done = false; count = 0; pos = -1; while (!done) { pos++; pos = myString.indexOf(char, pos); if (pos == -1) { done = true; } else { done = false; count++; } } return count; }
Oct 18, 2001 #3 Acer40 Programmer Oct 18, 2001 2 US I dont know if this could help function CountDuplicates(strStringToSearch, strFind) { var intStringPos = 0; var intStringCount = 0; while (intStringPos != -1) { intStringPos = strStringToSearch.indexOf(strFind, intStringPos + 1); intStringCount++; } return(intStringCount); } Upvote 0 Downvote
I dont know if this could help function CountDuplicates(strStringToSearch, strFind) { var intStringPos = 0; var intStringCount = 0; while (intStringPos != -1) { intStringPos = strStringToSearch.indexOf(strFind, intStringPos + 1); intStringCount++; } return(intStringCount); }