You may assign '\u0000' (or 0).
For this purpose, use Character.MIN_VALUE.
Character ch = Character.MIN_VALUE;
Answer from KV Prajapati on Stack OverflowSo i have been willing to learn to code for a long time and i started 4 days ago and im watching some youtube tutorials but my VisualStudio 2012 is typing ' ' instead of '' and it keep giving me Empty character literal error. Any solutions ? ( i already tried to google it but i couldnt understand a word)
So, strings are made up of characters. You can have literals of them both. Double-quotes indicate string literals, and single-quotes indicate character literals.
It's ok to have a zero-length string (""), but a zero-length character doesn't make any sense and isn't valid. This is what the compiler is telling you.
Bonus credit: Try not to use "" for empty strings - use String.Empty instead. It communicates your intent better, and reduces the chance of a space accidentally getting in there via typing error.
Use "" for the empty string. Single quotes need exactly one character between them.
'' doesn't make any sense. Try 'A' or 'z' or '%' or '.' instead.
You may assign '\u0000' (or 0).
For this purpose, use Character.MIN_VALUE.
Character ch = Character.MIN_VALUE;
char means exactly one character. You can't assign zero characters to this type.
That means that there is no char value for which String.replace(char, char) would return a string with a diffrent length.
Empty character literal Issue
Empty Character Literal - Post.Byes - Bytes
In java i tried replace char with ''. But it's showing "Empty Literal Character" error - Stack Overflow
Empty character literal Issue
You can't have a character representing nothing. You need a character sequence of length zero, i.e. an empty string.
As such, your first argument also needs to be converted to use the String, String signature.
name = name.replace(Character.toString(name.charAt(i)), "");
If you want to remove some specific characters, then you can try it this way:
//Convert String to CharArray
char[] ch = name.toCharArray();
String newName = "";
for (char c: ch) {
if (wantThisCharacter(c)) newName+=c;
}
name = newName;
The unicode code points in the source file are replaced by the actual character they represents. Since '\u0027' is for ' (apostrophe). So, your return statement is replaced to:
return s.replace('\u0092',''');
Note: \u0092 will also be replaced by control character.
So, the 2nd argument is an invalid character literal. You can rather use \' directly.
Replacing the unicode sequences is a very early step of the compilation process. In particular, it happens before parsing literals. So when it's time to parse the literals, \u0027 has already been replaced with '. Therefore, after the comma, you have ''', which the compiler can't make sense of.
The reason is that a character literal is defined as a character. There may be extensions that allow it to be more than one character, but it needs to be at least one character or it just doesn't make any sense. It would be the same as trying to do:
int i = ;
If you don't specify a value, what do you put there?
This is because an empty string still contains the the null character '\0' at the end, so there is still a value to bind to the variable name, whereas an empty character literal has no value.