Changeset 2385 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Mar 8, 2019, 4:41:18 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `remove_extraspaces': Function to remove from a string any chain of more or equal than 2 spaces
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2380 r2385  
    158158# Nstr: Function to transform a number to string, but making sure it preserves
    159159#   characteristics of the number
    160 # Ntchar: Function to repeat a number of times a given tring
     160# Ntchar: Function to repeat a number of times a given string
    161161# num_chainSnum: Function to pass a value to a `ChainStrNum' number
    162162# num_ordinal: Function to provide the ordinal of a given number, language, format and gender
     
    178178#   intervals for a sub-set of the dimensions in order to avoid memory problems
    179179# rectangular_spiral: Function to provide a rectangular spiral (along x,y-axis values) of values
     180# remove_extraspaces: Function to remove from a string any chain of more or equal than 2 spaces
    180181# remove_monotones: Function to remove the monotones (len(dim) = 1) from an array
    181182# replace_list: Function to replace a value in a given list
     
    1538315384#    for j in range(4):
    1538415385#        print '  ' , '(', inds[i,j,0], ',', inds[i,j,1], ')'
     15386
     15387def remove_extraspaces(string, maxNspaces=30):
     15388    """ Function to remove from a string any chain of more or equal than 2 spaces
     15389      string: string to modify
     15390      maxNspaces: maximum number of consecutive spaces to look for (30 default value)
     15391    >>> remove_extraspaces('  87047 01011991    6  19.0 6 70 7   27    2  17.9   874.9  1471.0              1    2      4 5  1  0      ')
     15392    87047 01011991 6 19.0 6 70 7 27 2 17.9 874.9 1471.0 1 2 4 5 1 0
     15393    """
     15394    fname = 'remove_extraspaces'
     15395
     15396    newstring = string + ''
     15397    for i in range(maxNspaces,1,-1):
     15398        spaces = Ntchar(' ',i)
     15399        newstring = newstring.replace(spaces, ' ')
     15400       
     15401    return newstring
     15402
    1538515403#quit()
    1538615404
Note: See TracChangeset for help on using the changeset viewer.