Skip to content

Add helper functions to get_text() between 2 markers and del_chars() [done] #259

@kensoh

Description

@kensoh

This is very useful when extracting text from a chunk of text content, by providing the left anchor and right anchor.

aisingapore/TagUI#972 (comment)

// retrieve text between 2 provided anchors in given text content
function get_text(source_text, left_marker, right_marker, optional_count) {
    if (!source_text || !left_marker || !right_marker) return '';
    var left_position = source_text.indexOf(left_marker); if (left_position == -1) return '';
    var right_position = source_text.indexOf(right_marker, left_position+1); if (right_position == -1) return '';
    if (optional_count > 1) {var occurrence_count = 2; while(occurrence_count <= optional_count) {occurrence_count++;
        left_position = source_text.indexOf(left_marker, right_position+1); if (left_position == -1) return '';
        right_position = source_text.indexOf(right_marker, left_position+1); if (right_position == -1) return '';}}
    return source_text.slice(left_position + left_marker.length, right_position).trim();}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions