Thread: Is there an off-the-shelf function to compute common string of string?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    Is there an off-the-shelf function to compute common string of string?

    Say I have
    Str1="/home/root/1.txt.tmp1.test"
    Str2="/home/root/2.txt.tmp2.test"
    Str3="/home/root/3.txt.tmp3.test"

    Is there an off-the-shelf function to get the common string of the strings?
    In this case: common_str="/home/root/*.txt.tmp*.test"

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    284
    To be specific, what I want is "Longest common subsequence" of multiple strings

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by meili100 View Post
    Say I have
    Str1="/home/root/1.txt.tmp1.test"
    Str2="/home/root/2.txt.tmp2.test"
    Str3="/home/root/3.txt.tmp3.test"

    Is there an off-the-shelf function to get the common string of the strings?
    In this case: common_str="/home/root/*.txt.tmp*.test"
    Actually, that is not the longest common substring at all. It's "/home/root/" - so you probably want to think in terms of a regular expression instead.

    Never the less, the problem you did mention has a pretty simple solution that you can write yourself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 6
    Last Post: 04-21-2006, 08:49 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM