That is sadly true, but at least for the Basic Multilingual Plane, charAt() and codePointAt() return correct results in constant time.
charat
How to use charat in a sentence. Live example sentences for charat pulled from indexed public discussions.
Editorial note
That is sadly true, but at least for the Basic Multilingual Plane, charAt() and codePointAt() return correct results in constant time.
Quick take
That is sadly true, but at least for the Basic Multilingual Plane, charAt() and codePointAt() return correct results in constant time.
Example sentences
For example, I don't think it's particularly bad that array[-1] and array.charAt(-1) return different values.
Linear-time indexing: operations like charAt require character indexing to be fast.
Or am I misinterpreting we have passed the burden of proof onto users of charAt?
Imagine if String.charAt(int index) was a virtual call inside of strlen().
String.length() and String.charAt() use utf-16 units, meaning surrogate pairs are double-counted.
Consider these examples: List<String> list = getListofStrings(); List<String> capitalized = new ArrayList<String>(); for(String st: list) if(Character.isUpperCase(st.charAt(0))) capitalized.add(st); Or...
- In the presence of surrogates, charAt() and length() give wrong answers.
If you have a longer list of N swears (say 256 because it's the size of a byte, making encoding easier), you could produce a more efficient base-N encoding, e.g.: var bytes = atob(base64msg), swearsMsg = ''; for (var i = 0; i < bytes.length; i++) { newMsg += swears[bytes[i].charAt(0)] + ' '; } Of course, it's still less efficient than base64, but it's an improvement.
Quote examples
However, for backward-compatibility reasons "charAt()" is defined to return a UTF-16 code-unit (regardless of whether or not it's a useless half-a-code-point) so effectively it's O(1) indexing.
The String#charAt() Javadoc is not really useful, unless you fully understand the implications of: "If the char value specified by the index is a surrogate, the surrogate value is returned." Also, if you are handling CJK strings, is there actually a need to split them by charAt()?
No, function InstructionParsing(instruction) { var separator = instruction.charAt(0) var instructionSplit = instruction.split(separator) this.clickSelector = instructionSplit[1] this.classBehavior = instructionSplit[2].trim().split(" ")[0] this.classValue = instructionSplit[3] this.targetSelector = instructionSplit[5] } is not "self-documenting." Tool is not useful but it is a cool study in writing a limited DSL.
I realize this is a straw man, but with heavy reliance on deep (3+ levels) of immutable relationships, it is not uncommon to find crap that is the equivalent of this: String foo = "hello"; Character bar = foo.charAt(0);...
Frequently asked questions
Short answers drawn from the clearest meanings and examples for this word.
How do you use charat in a sentence?
That is sadly true, but at least for the Basic Multilingual Plane, charAt() and codePointAt() return correct results in constant time.