CharSequence length - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for CharSequence length method.

This code example shows how to use the following methods:getSpans, charAt, length
		bypass.markdownToSpannable("");
	} 
 
	public void testHeaderString() { 
		Spannable spannable = (Spannable) bypass.markdownToSpannable("Header!!\n--------");
		StyleSpan[] spans = spannable.getSpans(0, spannable.length(), StyleSpan.class);
		assertEquals(1, spans.length);
		RelativeSizeSpan[] sizeSpan = spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class);
		assertEquals(1, sizeSpan.length);
		assertEquals('\n', spannable.charAt(spannable.length() - 1));
	} 
	 
	public void testBoldString() { 
		Spannable spannable = (Spannable) bypass.markdownToSpannable("One **Two** Three");
		StyleSpan[] spans = spannable.getSpans(0, spannable.length(), StyleSpan.class);
		assertEquals(1, spans.length);
		assertEquals(Typeface.BOLD, spans[0].getStyle());
		assertEquals(4, spannable.getSpanStart(spans[0]));
		assertEquals(7, spannable.getSpanEnd(spans[0]));
	} 
8
CodeRank
This code example shows how to use the following methods:getSpans, length, toString
        builder.setSpan(new CustomSpan(), 4, builder.length(), 0);
    } 
 
    private void checkPostProcess(Spanned ret) {
        // Newlines should be trimmed. 
        assertEquals("01234", ret.toString());
 
        // First, check the image span. 
        // - Vertical alignment should be changed to ALIGN_BASELINE 
        // - Drawable shouldn't be changed. 
        ImageSpan[] imageSpans = ret.getSpans(0, ret.length(), ImageSpan.class);
        assertEquals(1, imageSpans.length);
        assertEquals(ImageSpan.ALIGN_BASELINE, imageSpans[0].getVerticalAlignment());
        assertEquals(ColorDrawable.class, imageSpans[0].getDrawable().getClass());
 
        // QuoteSpans should be replaced with StreamItemQuoteSpans. 
        QuoteSpan[] quoteSpans = ret.getSpans(0, ret.length(), QuoteSpan.class);
        assertEquals(1, quoteSpans.length);
        assertEquals(StreamItemQuoteSpan.class, quoteSpans[0].getClass());
 

8
CodeRank
This code example shows how to use the following methods:removeSpan, setSpan, getSpanStart, length
        int length = output.length();
        output.setSpan(span, length, length, SPAN_MARK_MARK);
    } 
 
    private static void endSpan(Class<?> type, Editable output) {
        int length = output.length();
        Object span = getLast(output, type);
        int start = output.getSpanStart(span);
        output.removeSpan(span);
        if (start != length)
            output.setSpan(span, start, length, SPAN_EXCLUSIVE_EXCLUSIVE);
    } 
 
    /** 
     * Encode HTML 
     * 
     * @param html 
     * @return html 
     */ 
    public static CharSequence encode(final String html) {
8
CodeRank
This code example shows how to use the following methods:getSpans, length, toString
        builder.setSpan(new CustomSpan(), 4, builder.length(), 0);
    } 
 
    private void checkPostProcess(Spanned ret) {
        // Newlines should be trimmed. 
        assertEquals("01234", ret.toString());
 
        // First, check the image span. 
        // - Vertical alignment should be changed to ALIGN_BASELINE 
        // - Drawable shouldn't be changed. 
        ImageSpan[] imageSpans = ret.getSpans(0, ret.length(), ImageSpan.class);
        assertEquals(1, imageSpans.length);
        assertEquals(ImageSpan.ALIGN_BASELINE, imageSpans[0].getVerticalAlignment());
        assertEquals(ColorDrawable.class, imageSpans[0].getDrawable().getClass());
 
        // QuoteSpans should be replaced with StreamItemQuoteSpans. 
        QuoteSpan[] quoteSpans = ret.getSpans(0, ret.length(), QuoteSpan.class);
        assertEquals(1, quoteSpans.length);
        assertEquals(StreamItemQuoteSpan.class, quoteSpans[0].getClass());
 

8
CodeRank
This code example shows how to use the following methods:length, subSequence
                    dstart, dend);
            if (filtered == null) {
                filtered = source.subSequence(start, end);
            } 
 
            String result = String.valueOf(dest.subSequence(0, dstart))
                + filtered + dest.subSequence(dend, dest.length());
 
            if ("".equals(result)) {
                return result;
            } 
 
            if (getMaxDigits() > 0 && result.length() > getMaxDigits())
                return ""; 
 
            int val = getSelectedPos(result);
 
            /* 
             * Ensure the user can't type in a value greater than the max 
             * allowed. We have to allow less than min as the user might want to 
7
CodeRank
This code example shows how to use the following methods:length
            mDeviceNameUpdated = false;
            mOkButton.setEnabled(false);
        } else { 
            mDeviceNameEdited = true;
            if (mOkButton != null) {
                mOkButton.setEnabled(s.length() != 0 && !(s.toString().trim().isEmpty()));
            } 
        } 
    } 
 
    /* Not used */ 
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    } 
 
    /* Not used */ 
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    } 
} 
6
CodeRank
This code example shows how to use the following methods:append, insert, setSpan, length, toString
            handleListTag(output);
    } 
 
    private void handleListTag(Editable output) {
        if (mListParents.lastElement().equals("ul")) {
            output.append("\n");
            String[] split = output.toString().split("\n");
 
            int lastIndex = split.length - 1;
            int start = output.length() - split[lastIndex].length() - 1;
            output.setSpan(new BulletSpan(15 * mListParents.size()), start,
                    output.length(), 0);
        } else if (mListParents.lastElement().equals("ol")) {
            mListItemCount++;
 
            output.append("\n");
            String[] split = output.toString().split("\n");
 
            int lastIndex = split.length - 1;
            int start = output.length() - split[lastIndex].length() - 1;

7
CodeRank
This code example shows how to use the following methods:replace, equals, length
	// IMPLEMENTATION 
	////////////////////////////////////////////////////////////////////////////////////// 
 
	@Override 
	public void afterTextChanged(Editable s) {
		String filtered = mMaskFormatter.valueToString(s);
		Log.t("original: %s - filtered: %s", s, filtered);
 
		if (!TextUtils.equals(s, filtered)) {
			s.replace(0, s.length(), filtered);
		} 
	} 
 
	@Override 
	public void beforeTextChanged(CharSequence s, int start, int count, int after) {
	} 
 
	@Override 
	public void onTextChanged(CharSequence s, int start, int before, int count) {
	} 
8
CodeRank
This code example shows how to use the following methods:setSpan, length
        header = serverName.toUpperCase();
        setText(header);
    } 
 
    public void setDisconnected() { 
        Spannable wordToSpan = new SpannableString(header + " (DISCONNECTED)");
        wordToSpan.setSpan(new ForegroundColorSpan(0xFFFF4444), header.length(), wordToSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setText(wordToSpan);
    } 
 
    public void setConnected() { 
        setText(header);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:length
		mMaxLength = maxLength;
	} 
 
	@Override 
	public void afterTextChanged(Editable s) {
		if (s.length() >= mMaxLength) {
			mView.focusSearch(View.FOCUS_FORWARD).requestFocus();
		} 
	} 
 
	@Override 
	public void beforeTextChanged(CharSequence s, int start, int count, int after) {
	} 
 
	@Override 
	public void onTextChanged(CharSequence s, int start, int before, int count) {
	} 
} 
6
CodeRank

Related CharSequence length Questions & Answers:

length Method Overview
Returns the length of this character sequence.
See Code Examples for other Java 8 CharSequence Methods: