removeExtraSpacesLF

removeExtraSpacesLF removes extra spaces and selected carriage returns from input string

Syntax

  • newTxt=removeExtraSpacesLF(txt)example

Description

Given an input string possibly containing a series of carriage returns (CR) and white spaces, removeExtraSpacesLF removes all carriage returns except those when:

1) symbol ';' is followed by one or more spaces and a CR;

2) symbol ':' is followed by one or more spaces and a CR;

3) symbol '.' is followed by one or more spaces and a CR;

4) symbol '

\[' is followed by one or more spaces and a CR; 5) symbol '\]

' is preceded by one or more spaces and a CR.

6) symbol '\\' is preceded by one or more spaces and a CR.

example

newTxt =removeExtraSpacesLF(txt) Create a string with unnecesseray line feeds and without text justification.

Examples

expand all

  • Create a string with unnecesseray line feeds and without text justification.
  • Create an input string containing a series of unwanted features. The input string is extracted from the head of the FSDA function tclust.m.

        FileWithFullPath=which('tclust');
        filename=FileWithFullPath;
        fileID = fopen(char(filename), 'r');
        fstring=fscanf(fileID,'%c');
        % Starting and ending lines
        aa=regexp(fstring,'tclust partitions the points') ;
        bb=regexp(fstring,'constrained, Mahalanobis distances\.');
        % String
        str=fstring(aa:bb+35);
    
        % Remove from string all percentage signs
        posPercentageSigns=regexp(str,'%');
        str(posPercentageSigns)=[];
    
        str=[str 'x0ANow some wanted line feeds: x0A first item;   x0A   second item.'];
        str=regexprep(str,'x0A','\x0A');
    
        % Remove unnecessary spaces and extra line feeds from str but just keep
        % line break if before there was ':' or ';' or '.'
        a=removeExtraSpacesLF(str)
    

    Related Examples

  • Create a string with a series of Latex equations.
  • The input string is extracted from the FSDA function tclust.m.

        FileWithFullPath=which('tclust');
        filename=FileWithFullPath;
        fileID = fopen(char(filename), 'r');
        % Insert the file into fstring
        fstring=fscanf(fileID,'%c');
        aa=regexp(fstring,'\\\[','once') ;
        bb=regexp(fstring,'\\\]','once');
        str=fstring(aa-145:bb+560);
        % Remove from string descri all percentage signs
        posPercentageSigns=regexp(str,'%');
        str(posPercentageSigns)=[];
        
        % str is the input string containing a series of Latex equations
        a=removeExtraSpacesLF(str)
    

    Input Arguments

    expand all

    txt — Input text. Character vector.

    String which has to be analysed.

    Data Types: single| double

    Output Arguments

    expand all

    newTxt —Output text. Character

    String without unwanted carriage returns and extra spaces, as in cases 1-5 above.

    References

    See Also

    |

    This page has been automatically generated by our routine publishFS