Manual Reference Pages  - quote (3m_strings)

NAME

quote(3f) - [M_strings:QUOTES] add quotes to string as if written with list-directed output (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

function quote(str,mode,clip) result (quoted_str)

   character(len=*),intent(in)          :: str
   character(len=*),optional,intent(in) :: mode
   logical,optional,intent(in)          :: clip
   character(len=:),allocatable         :: quoted_str

DESCRIPTION

Add quotes to a CHARACTER variable as if it was written using list-directed output. This is particularly useful for processing strings to add to CSV files.

OPTIONS

str input string to add quotes to, using the rules of list-directed output (single quotes are replaced by two adjacent quotes)
mode alternate quoting methods are supported:
            DOUBLE   default. replace quote with double quotes
            ESCAPE   replace quotes with backslash-quote instead of
                     double quotes

clip default is to trim leading and trailing spaces from the string. If CLIP is .FALSE. spaces are not trimmed

RETURNS

quoted_str
  The output string, which is based on adding quotes to STR.

EXAMPLES

Sample program:

   program demo_quote
   use M_strings, only : quote
   implicit none
   integer                      :: i
   character(len=*),parameter   :: f=’(*(g0))’
   character(len=:),allocatable :: str
   character(len=80),parameter  :: data(3)=[character(len=80)::&
      ’test string’,&
      ’quote="’,&
      ’"word1" "word2"’]
      do i=1,size(data)
         ! the original string
         write(*,’(a)’)’ORIGINAL      ’//trim(data(i))

! the string processed by quote(3f) str=quote(data(i)) write(*,’(a)’)’QUOTED ’//str

! write the string list-directed to compare the results write(*,f,advance=’no’) ’LIST DIRECTED’ ! default is often NONE or APOSTROPHE write(*,*,delim=’quote’) trim(data(i)) enddo end program demo_quote

Results:

 > ORIGINAL      test string
 > QUOTED        "test string"
 > LIST DIRECTED "test string"
 > ORIGINAL      quote="
 > QUOTED        "quote="""
 > LIST DIRECTED "quote="""
 > ORIGINAL      "word1" "word2"
 > QUOTED        """word1"" ""word2"""
 > LIST DIRECTED """word1"" ""word2"""

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 quote (3m_strings) July 20, 2024
Generated by manServer 1.08 from 81747c9b-506d-4cd2-b9ad-8396d81d9329 using man macros.