Hello, I have a problem where I need to delete any occurrence of "~" from a string. I created a function but in the end, it only deletes half of the "~" and leaves the other half....
string goodstring(string inp)
{
for (int i = 0; i < strlen(inp.c_str()); i++)
{
if (inp[i] >= 0x41 && inp[i] <= 0x5A)
{
inp[i] += 0x20;
}
}
for (int i = 0; i < strlen(inp.c_str()); i++)
{
if (inp[i] >= 32 && inp[i] <= 47)
{
inp[i] = 126;
}
}
for (int i = 0; i < strlen(inp.c_str()); i++)
{
if (inp[i] >= 58 && inp[i] <= 64)
{
inp[i] = 126;
}
}
for (int i = 0; i < strlen(inp.c_str()); i++)
{
if (inp[i] >= 91 && inp[i] <= 96)
{
inp[i] = 126;
}
}
for (int i = 0; i < strlen(inp.c_str()); i++)
{
if (inp[i] >= 123 && inp[i] <= 126)
{
inp[i] = 126;
}
}
for (int i = 0; i < strlen(inp.c_str()); i++)
{
if (inp[i] >= '0' && inp[i] <= '9')
{
inp[i] = 126;
}
}
for (int i = 0; i < strlen(inp.c_str()); i++)
{
if (inp[i] == 126)
{
inp.erase(inp.begin() + i, inp.begin()+i+1);
}
}
return inp;
}
So what I basically do is read a string, and go like
input = goodstring(input);
Can someone help me sort this problem? Also I just realized that I don't actually need that many for loops.. Sorry.