N
N
NameOf Var2016-12-14 22:58:21
Java
NameOf Var, 2016-12-14 22:58:21

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);

In the current example, with buffer = "ach" it will output:
b defg

And should output without a space:
bdefd

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VIDEN22014, 2020-03-19
@VIDEN22014

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 question

Ask a Question

731 491 924 answers to any question