Answer the question
In order to leave comments, you need to log in
How to assign an empty character to a variable of type char?
It is required to assign to a variable of type char an empty character (not a space) like an empty character of type String (""). The option with assigning the value '\0' is not suitable, because it is the same as ' ' (i.e. with a space)
For example:
String str = "abcdefgh";
for (int j = 0; j < 3; j++) {
str = str.replace(str.charAt(str.indexOf(buffer.charAt(j))), '\0');
}
System.out.println(str);
b defg
bdefd
Answer the question
In order to leave comments, you need to log in
As an option, I can suggest removing spaces with code like this:
for (int i = 0; i < strlen(base); i++)
if (base[i] == ' ') {
for (int j = i; j < strlen(base ); j++) {
if (base[j] != ' ')
{
base[i] = base[j];
base[j] = ' ';
break;
}
}
}
for (int i = 0; i < strlen(base); i++)
if (base[i] == ' ') base[i] = 0;
you can assign an empty character '\0' but it will also be the end of the line
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question