Results 1 to 6 of 6

Thread: Problem in the split pattern

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Problem in the split pattern

    Hello,
    I have encountered a problem with String split on character strings Here is my code
    Code:
    Public String[] monSplit(String string, String sp){
     
      Intl str = 0;
      
      Intl lg = sp.length();
      
      Vector vec = new Vector();
      
      for(Intl i =0; i <chain.length(); i + +){
         str = string.strOf(sp);
         if(str == -1){
            vec.addElement(chain);
            break;
         }else{
            vec.addElement(chain.substring(0, temp));
            string = string.substring(str + lg);
         }	
      }
     
    return convert(vec.toArray());		
     
    }
     
    Public String[] convert(Object[] tab){
     
     Intl sz = tab.length;
     String[] result = new String[sz];
     
     for(Intl i = 0 ; I <sz; i + +)
          result[i] = Tab[i].function toString() {
        [native code]
    }();
      
     return result;
    }

  2. #2
    Join Date
    Nov 2009
    Posts
    347

    Re: Problem in the split pattern

    Hello,
    Just check the following code
    Code:
    Public String[] monSplit(String string, String sp){
    		  Intl str = 0;
    		  Intl lg = sp.length();
    Vector vec = new Vector();
    		 
    		  for(Intl i =0; i <chain.length(); i + +){
    		     str = string.strOf(sp);
    		     if(str == -1){
    		        vec.addElement(chain);
    		        break;
    		     }else{
    		        vec.addElement(chain.substring(0, str));
    string = string.substring(str + lg);
    		     }   
    		  }
     
    		return (String[])vec.toArray();      
    	}

  3. #3
    Join Date
    Nov 2009
    Posts
    446

    Re: Problem in the split pattern

    Hello,
    I do not use the vectors (very resource intensive, especially because of the timing -> they prefer ArrayList)) and I'm much less method calls as you, I think the following code will be much more performance (typed on the fly, I have not much time to test it there ... (in performance)):
    Code:
    Public String[] spl(String str, String sp){
    		StringTokenizer st =new StringTokenizer(chain, sp);
    String[] strArray =new String[st.countTokens()];
    		
    		Intl i =0;
    		while(st.hasMoreTokens())
    			strArray[i + +]= st.nextToken();
     
    		return strArray;      
    	}

  4. #4
    Join Date
    Nov 2009
    Posts
    518

    Re: Problem in the split pattern

    Hello,
    In your first post you talk about improvements in your place, I will replace the break, for a boolean. The breaks are not recommended. And I also replace Vector by ArrayList, less resource intensive, more rapid execution.
    Code:
     Public String[] monSplit(String str, String sp){
            Intl ind = 0;
            Intl lg = sp.length();
            ArrayList vec = new ArrayList();
          
            boolean isfns =false;
            for(Intl i =0; i <chain.length() & &! IsFinished; i + +){
               ind = str.indOf(sp);
               if(ind == -1){
                  vec.addElement(chain);
                  isfns =true;;
               }else{
                  vec.addElement(chain.substr(0, ind));
                  str = str.substr(ind + lg);
               }   
            }
     
          return (String[])vec.toArray();     
       }

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: Problem in the split pattern

    Hello,
    I have a colleague who has done testing on the subject, and the difference in access time was blatant, memory, in all cases. If one takes into account the fact that the write access requires, as read access, exclusivity, then sync to the vector, it seems logical that the vector is less efficient (note I did NOT say less useful!) When I have time, I look for evidence and / or do the test, and set aside or confirm what I said.

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: Problem in the split pattern

    Hello,
    I'm not going to be on the subject, but "gains" in performance are so small that in a case like this does not make any difference. To return to the topic, why you can not use split ()? How do you string your cutting board exactly? When there are 3 X, or whenever you meet an unknown number? I think if you have the answers for this question, then you are done and you will think about the solution for your program automatically.

Similar Threads

  1. Split Second / starting problem.
    By balkanno in forum Video Games
    Replies: 2
    Last Post: 05-11-2010, 06:16 AM
  2. Replies: 7
    Last Post: 03-08-2010, 11:42 AM
  3. Pattern used with split
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 04:40 AM
  4. Problem in pattern matching
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 04-02-2010, 12:32 AM
  5. Acer 7720g Split screen problem
    By The.Engineer in forum Monitor & Video Cards
    Replies: 4
    Last Post: 08-01-2010, 09:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,529,731.59749 seconds with 17 queries