Trying to get my head around this. If I have a word string that can contain any word how can I return a variable that provides the number of different letters contained in that word.
Example:
var number_of_different_letters;
string myword = "potatoe"; // the word string myword2 = "rocket"; // another word
Is it possible to assign the number of different letters from these strings into the variable number_of_different_letters?
So for
myword: number_of_different_letters = 5; since there are 2 instances of t and 0
myword2: number_of_different_letters = 6;// all different letters
Would appreciate any help.
best regards,
Rob
Re: different letters in a word string
[Re: robertbruce]
#366697 04/06/1113:5204/06/1113:52
during a boring telephone conference I typed this in notepad - so it is neither tested nor compiled, but the principle should work.
Code:
var different_letters(char* s)
{
var letterflag[256];
var count = 0;
var i,l;
l=str_len(s);
for (i=0;i<l;i++) {letterflag[i]=TRUE};
for (i=0;i<l;i++)
{
if (letterflag[(integer)(s[i])])
count++;
else
letterflag[(integer)(s[i])]=FALSE;
}
return (count);
}
Uuups - this is the C-Script forum. I opened your post from the "Newest Posts" section and did not recognize this. Well, I don't speak C-Script, but I hope the differences are not too big.