i have to look for all the char possible in string and get those char position but can't seem to figure out how look for all char. i tried using str.find but it only looks for the first one in whole string
I assume you mean you want to count all occurrences of a particular character in a string? If so, do something like this...
1 2 3 4 5 6 7 8 9 10 11 12
string x = "This is a test.";
char searchItem = 't';
int numOfChar = 0;
int length = strlen(x);
for(int i = 0;i < length;i++)
{
if(x[i] == searchItem)
{
numOfChar++;
}
}
Whereas "numOfChar" would be the integer that stores the number of occurrences of that character and "searchItem" would be the char you're looking for. To check for both the uppercase and lowercase instances of that particular letter, just make it check for the char converted using tolower() and the char converted using toupper().
im sorry i wasn't clear i don't wanna know the occurrences for char but position of char. for example
string my_string= "blasddsdfsl"
and i want to search for char 'd'. i want to know the position of every char 'd' in that string
because the second string holds blanks '-' for every char in first string "blasddsdfsl" and after i search for char in that string i have to replace that char with blanks in that second string. u get it?
So essentially you're replacing every occurrence of a character with another? If so, this can be done in a loop similar to what PacketPirate posted about 5 posts up.