aspose file tools
The moose likes Java in General and the fly likes split a string using delimiter..truncate each segment and append Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "split a string using delimiter..truncate each segment and append" Watch "split a string using delimiter..truncate each segment and append" New topic
Author

split a string using delimiter..truncate each segment and append

Preetish Panda
Greenhorn

Joined: May 10, 2010
Posts: 9
Hello.. this is my first post here ..I'll explain what I want to accomplish using an example

Suppose I have a string C:\check out\checking out\BACKUPER

Now I'll split it using delimiter as \ .
So it will become

  • C:

    check out

    checking out

    BACKUPER


  • "check out" and "checking out" contain space.The code will remove the space and convert
    them into "checkout" and "checkingout".

    Then truncate them into strings of 6 characters and append ~1.

    Finally they will be become checko~1 and checki~1.

    BACKUPER doesn't contain space.So, it will remain as it is.

    Finally all will be appended and result will be C:\checko~1\checki~1\BACKUPER


    Can any one suggest me an approach or any function that will make this adventure like a cake walk ??

    Thanks in advance ..
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14669
        
      11

    Welcome to the ranch !
    If you look at the java.lang.String API, you'll have most (all?) of the tools you need.


    [My Blog]
    All roads lead to JavaRanch
    David Newton
    Author
    Rancher

    Joined: Sep 29, 2008
    Posts: 12617

    Seems like you have all the steps--what, specifically, are you having a problem with?

    Be careful with this algorithm, though--what would happen if you had these two directories?

    c:\check out\foo
    c:\check out this\foo
    Preetish Panda
    Greenhorn

    Joined: May 10, 2010
    Posts: 9
    David Newton wrote:Seems like you have all the steps--what, specifically, are you having a problem with?

    Be careful with this algorithm, though--what would happen if you had these two directories?

    c:\check out\foo
    c:\check out this\foo


    For the directories given by you ... according my algorithm it will be
    c:\checko~1\foo
    c:\checko~1\foo

    As foo is devoid of space.

    I was just looking for some tip or approach that will be quite easy.
    David Newton
    Author
    Rancher

    Joined: Sep 29, 2008
    Posts: 12617

    Right, what I'm saying is that the two different directories would map to the same shortened string, which is a Bad Thing.
    Preetish Panda
    Greenhorn

    Joined: May 10, 2010
    Posts: 9
    David Newton wrote:Right, what I'm saying is that the two different directories would map to the same shortened string, which is a Bad Thing.


    Ok.. In my case this kind of scenario won't arise.
    Raza Mohd
    Ranch Hand

    Joined: Jan 20, 2010
    Posts: 247




    hi ,

    I hope this could help.
    I tried to get the desired output.

    regards
    raza!


    Good luck!!
    A small leak can sink a Gigantic ship.>
    David Newton
    Author
    Rancher

    Joined: Sep 29, 2008
    Posts: 12617

    @Raza: Please don't provide complete solutions. Our goal on JavaRanch is to help people learn how to learn, figure out problems, and so on--rather than just do somebody's work for them, encourage them to spend some quality time on it themselves, try various solutions, etc. Thanks.
    Raza Mohd
    Ranch Hand

    Joined: Jan 20, 2010
    Posts: 247

    okay Newton,

    i will not do it again,
    it was my mistake.

    thanks
    raza!
    Ritesh Pareek
    Ranch Hand

    Joined: Nov 04, 2008
    Posts: 50
    For the directories given by you ... according my algorithm it will be
    c:\checko~1\foo
    c:\checko~1\foo


    No, This must be like


    c:\checko~1\foo
    c:\checko~2\foo

    java.lang.String API having this solution. Algo should be look like this

    loop1 while mainStr not null
    resArr[count++] = mainStr.slice(indexof("\\"))
    end Loop2


    loop2 while resArr

    1. you can use selection/binary sorting here
    2. truncate tailing chars with ~1
    3. do compare array element for 8 char similar string.
    4. if similar truncate tailing chars with ~2,3,4... so on
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 32599
        
        4
    Apology accepted, on behalf of JavaRanch
    Preetish Panda
    Greenhorn

    Joined: May 10, 2010
    Posts: 9
    Ritesh Pareek wrote:
    For the directories given by you ... according my algorithm it will be
    c:\checko~1\foo
    c:\checko~1\foo


    No, This must be like


    c:\checko~1\foo
    c:\checko~2\foo

    java.lang.String API having this solution. Algo should be look like this

    loop1 while mainStr not null
    resArr[count++] = mainStr.slice(indexof("\\"))
    end Loop2


    loop2 while resArr

    1. you can use selection/binary sorting here
    2. truncate tailing chars with ~1
    3. do compare array element for 8 char similar string.
    4. if similar truncate tailing chars with ~2,3,4... so on


    You are not getting me .In my case there will be only one string and only ~1 has to be appended.
    No question of ~2,~3,...

    Thanks for your suggestion.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: split a string using delimiter..truncate each segment and append
     
    Similar Threads
    Regex and split method question
    criteria string
    How to set width of cells in excel on browser ?
    String.split Vs StringTokenizer
    cell formatting in excel using jsp