getCommonPrefix          package:Rlibstree          R Documentation

_C_o_m_p_u_t_e _t_h_e _l_o_n_g_e_s_t _c_o_m_m_o_n _p_r_e_f_i_x _o_f _t_h_e _g_i_v_e_n _s_t_r_i_n_g_s

_D_e_s_c_r_i_p_t_i_o_n:

     This function finds the longest common prefix shared by the input
     strings. This is different from finding the longest common
     substring as here we are insisting that this occur at the
     beginning of each of the strings. This uses a straightforward
     search, terminating whenever it finds a mismatch in any of the
     strings.

_U_s_a_g_e:

     getCommonPrefix(words, asCharacter = TRUE, na.rm = TRUE)

_A_r_g_u_m_e_n_t_s:

   words: a character vector containing the strings of interest

asCharacter: a logical value which if 'TRUE' means that the actual
          prefix is returned. Otherwise, the number of characters in
          the prefix is returned and this can be used to compute the
          substring or for some other purpose. 

   na.rm: a logical value indicating whether to remove 'NA's. If this
          is 'FALSE' and there are 'NA' elements in 'words', an error
          is raised.

_V_a_l_u_e:

     If 'asCharacter' is 'TRUE', a character vector giving the actual
     prefix. If there is no common prefix, this is the empty character
     vector.

     If 'words' is empty, this returns the empty character vector if
     'asCharacter' is 'TRUE' and 0 otherwise.

     If 'asCharacter' is 'FALSE', this returns a scalar integer giving
     the position  of the end character of the common prefix string.

_A_u_t_h_o_r(_s):

     Duncan Temple Lang <duncan@wald.ucdavis.edu>

_R_e_f_e_r_e_n_c_e_s:

     <URL: http://www.omegahat.org/Rlibstree>

_S_e_e _A_l_s_o:

     'getLongestCommonSubstring'

_E_x_a_m_p_l_e_s:

        # The names of enumerated constants in Microsoft Word's
        # scripting interface.  We want to find the common prefix.
     enumNames = c('wdSummaryModeHighlight',
                   'wdSummaryModeHideAllButSummary',
                   'wdSummaryModeInsert',
                   'wdSummaryModeCreateNew')

      getCommonPrefix(enumNames)

