How to split string based on either space or tab delimitation?

I'm trying to split a string into 4 fields.  The strings sometimes have space delimitation and sometimes have tab delimitation.  Is there any way to do this in a SELECT, or do I need a couple staging tables, or what?
I'm trying to work with this.
Select PARSENAME(replace(replace(replace(replace([Column 0],' ','<>'),'><',''),'char(9)',' '),' ','.'),4) Date,
PARSENAME(replace(replace(replace(replace([Column 0],' ','<>'),'><',''),'char(9)',' '),' ','.'),3) ID,
PARSENAME(replace(replace(replace(replace([Column 0],' ','<>'),'><',''),'char(9)',' '),' ','.'),2) Rank1,
PARSENAME(replace(replace(replace(replace([Column 0],' ','<>'),'><',''),'char(9)',' '),' ','.'),1) Rank2
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

This is similar thread that someone posted a week ago
Split delimited string into separate columns
based on space
My solution was, using a user defined function to split the text:
Use Master
Go
CREATE FUNCTION dbo.udf_SplitString(@InputVal VARCHAR(200), @Delimiter CHAR(1))
RETURNS @Items TABLE (RowNo TINYINT, ITEM VARCHAR(100))
As
BEGIN
DECLARE @FieldLen TINYINT = 0, @FieldEnum TINYINT = 0, @TempItem VARCHAR(100) = '', @ItemLoop TINYINT = 1
SET @FieldLen = LEN(@InputVal)
WHILE @FieldEnum <= @FieldLen
BEGIN
IF (SUBSTRING(@InputVal, @FieldEnum + 1, 1) = @Delimiter OR @FieldEnum = @FieldLen) AND @TempItem <> ''
BEGIN
INSERT @Items (RowNo, Item)
VALUES (@ItemLoop, LTRIM(RTRIM(@TempItem)))
SET @TempItem = ''
SET @ItemLoop += 1
END
ELSE
BEGIN
IF SUBSTRING(@InputVal, @FieldEnum + 1, 1) <> @Delimiter
BEGIN
SET @TempItem = @TempItem + SUBSTRING(@InputVal, @FieldEnum + 1, 1)
END
END
SET @FieldEnum += 1
END
RETURN
END
Next, use the splited data to group based on requirements
DECLARE @AllData TABLE
[Column 0] VARCHAR(50)
INSERT INTO @AllData
VALUES('20150101 04559690 45 33')
INSERT INTO @AllData
VALUES('20150101 045595320 42 48')
INSERT INTO @AllData
VALUES('20150101 041198690 44 34')
INSERT INTO @AllData
VALUES('20150101 0455222130 41 49')
INSERT INTO @AllData
VALUES('20150101 554567450 40 51')
;WITH CTE
AS
SELECT
,Row_Number() OVER(PARTITION BY MainQry.[Column 0] ORDER BY MainQry.[Column 0]) As RowNo
FROM
@AllData As mainQry
CROSS APPLY (SELECT Item FROM Master.dbo.udf_SplitString(REPLACE(MainQry.[Column 0], CHAR(9), ' '), ' ')) As SubQry
SELECT
[Column 0]
,MAX(CASE WHEN RowNo = 1 THEN Item ELSE '' END) AS [DATE]
,MAX(CASE WHEN RowNo = 2 THEN Item ELSE '' END) AS [ID]
,MAX(CASE WHEN RowNo = 3 THEN Item ELSE '' END) AS [Rank1]
,MAX(CASE WHEN RowNo = 4 THEN Item ELSE '' END) AS [Rank2]
FROM
CTE
GROUP BY
[Column 0]
Output
Column 0 | DATE
| ID
| Rank1 | Rank2
20150101 0455222130
41 49
| 20150101
| 0455222130
| 41 | 49
20150101 554567450
40 51
| 20150101
| 554567450
| 40 | 51
20150101 041198690 44  34
| 20150101
| 041198690
| 44 | 34
20150101 045595320 42   48
| 20150101
| 045595320
| 42 | 48
20150101 04559690 45  33
| 20150101
| 04559690 | 45
| 33
Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.

Similar Messages

  • Split string based on number of characters

    Hi,
    I have a simple map where I receive a Streetname out of the source and have to write that streetname to the Address1 element in the destination. The issue is that the destination Address1 element can only contain 100 characters.
    If it has more then 100 characters then I have to split the string into the Address2 element.
    The next question is how I can do it the good way so that the string would be split between spaces and not in the middle of a word. For example:
    Streetname1 Streetname2 Streetname3 Streetname4 Streetname5 Streetname6 Streetname7 Streetname8 Streetname9
    The hundredth character is between t and r in Streetname9. So the cleanest solution would be to place everything in address1 and Streetname9 in address 2.
    How can I achieve this?

    I had faced a similar situation in which output element could only contain 100 characters after that i had to split rest of characters in batch of 100 characters and repeated the element.
    This was achieved by implementing recursion through XSLT. For this I created a template which will return a substring a generate an element with that element. This template will take two parameters-1) Complete string 2) Length (100 in your case).
    check the below article for a sample
    http://www.codeproject.com/Articles/16866/Recursive-XSL-Templates
    Thanks,
    Prashant
    Please mark this post accordingly if it answers your query or is helpful.

  • How to split string into element ?

    How do you split common string ??
    String dd = "aaa";
    dd.split("a");  // result ["a","a","a"]

    args[0] will not take the entire string Test Hello
    World. It will take only Test, so only one element in
    the string array.What are you talking about?
    He's running the Test program which receives two arguments:
    args[0] = "Hello"
    args[1] = "World"
    But I'm pretty sure he knew that as he lead his post with:
    "Ever have one of those Doh moments"

  • How to Split string ("39934,,\"VIE\",\"Cong, hoa, xa, hoi\"") ???

    My string is:
    String string = "39934,,\"VIE\",\"Cong, hoa, xa, hoi\""
    Now, i want to split into array:
    a[0]="39934"
    a[1]=""
    a[2]="\"VIE\""
    a[3]="\"Cong, hoa, xa, hoi\""
    How i do?

    thanhhaunv wrote:
    Now, i want to split into array:
    a[0]="39934"
    a[1]=""
    a[2]="\"VIE\""
    a[3]="\"Cong, hoa, xa, hoi\""[String.split()|http://java.sun.com/javase/6/docs/api/java/lang/String.html#split%28java.lang.String%29] will do the basics for you; but it's naive.
    ie, If any of your quoted strings contain commas and you don't want them split, you'll have to put them back together in a step 2.
    Winston

  • How to save string inArraylist without precious space

    While adding the string in a arraylist , a blank space is inserted between the elements . But for my scenario i dont want to add a space. How do i rectify this. Please help me.

    prometheuzz wrote:
    Saish wrote:
    I was confused why toString() had even entered the discussion. ...I don't see what other extra space it could be other than the toString() representation of the collection.
    But it could be something entirely different of course...Yeah, I also thought the OP might have inserted a blank space as an element or a null or empty string or something similar. It's hard to say without knowing more about the problem.
    - Saish

  • Read text from file, created string, but don't know how to split string.

    I've been busy with a little application which should be able to save a (2d) array to a text file, and open it afterwards.
    I already completed both steps, but i'm stuck at the reading part.
    I'm not familiar with the load function, so i used Datainputstream, which i've converted to a String afterwards. The systemconsole shows the correct information when I put the string to the console, but now i want to split the string.
    For example, my console writes:
    FILE CONTENT=458,304,0,345,432
    ("FILE CONTENT=" has been manually added to the system.out)
    Because im not English, and i don't know what I should search for on the web in order to find this, i've come up here and created this post.
    I've got an object array which is 2-dimensional, and now i was wondering how i could "rebuild" my array array[x][c] in which the first number of my file content should be X and the other numbers should be put in [c].
    Offcourse, the ',' should be skipped.
    I do have read things about tokenizing and so on, but i think that every single letter is read then.
    Any help would be much appreciated.

    Ok, thanks for the reply.
    I feel a bit ashamed now, because my topic title contains the function i needed...
    So, assuming that i would have
    String content = "458,304,0,345,432";i could split this and put this in an array string using a code like
    String[] arry = null;
    array = content.split("\\.");I haven't tested the code yet, cause i'll go to bed soon, but will this split all at once and put it in the array or do i have to create a loop or something ?
    And is it possible to put number one using split in the array[x][v] on the x location and the others at the [v] location ? (the first number of each five has to be added to [x] and the other 4 to [v] )
    Again thanks for your reply, cause im a bit further this way in accomplishing what i want to reach :)

  • Newbie Question: Rules: Functions: How to compare String based type?

    I have some XML facts in my rules dictionary defined by the following schema (fragments shown)
    <xs:simpleType name="VarType">
       <xs:restriction base="xs:string">
          <xs:enumeration value="Foo"/>
          <xs:enumeration value="Bar"/>
          <xs:enumeration value="Baz"/>
          <xs:enumeration value="Qux"/>
       </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="ProgType">
       <xs:sequence>
          <xs:element name="ID" type="xs:string"/>
          <xs:element name="var" type="VarType" maxOccurs="unbounded"/>
       </xs:sequence>
    </xs:complexType>
    Which means that a Prog of ProgType has an ID and a "list" of "var" strings restricted to bounds specified by VarType.
    The issue comes when I try to create a Rules Function operating on these types.
    Function-> boolean containsVar(ProgType prog,VarType var) (built using the Functions tab of the Rules editor)
    for (String v : prog.var ){
       if (v == var){
          return true
    return false
    The problem we run into here is typing. If v is declared a String, as here, then v == var is invalid because types don't match. But I can't declare v a VarType due to
    RUL-05583: a primitive type or fact type is expected, but neither can be found.
    This problem may stem from the fact the Java's String is declared final and can't be subclassed, so the JAXB translation to Java may have to wrap it, futzing ==/equals() in the process.
    SO... How do I create this method and compare these values?
    TIA
    Edited by: wylderbeast on Mar 10, 2011 9:15 AM - typos
    Edited by: wylderbeast on Mar 10, 2011 9:18 AM

    And here's the answer.
    var.value() seems to return the String value of the type
    so the comparison becomes
    (v == var.value())
    Live and learn....

  • How to Split String

    Hi,
        I have a string with fields each of length 40, I need to split it at the mutilples of 40  and put in an internal table , i.e.
    field1(40),
    field2(40),
    field3(40)
    v_str = (field1                                  field2                               field3                  ..  ).
    thanks
    points will rewarded

    DATA: s1 TYPE string,
    s2 TYPE string,
    s3 TYPE string,
    it_tab TYPE TABLE OF string,
    text = ` ur text `.
    SPLIT text AT ',' INTO: s1 s2 s3,
    TABLE it_tab.
    Regards,
    Jagadish

  • How to split string in data table row in c#

    hi,
    Binding List data in to data table,. in that table i have description column. this column data move to data table in sql server
    here we facing problem for Description column
    the description column having data is
    <div class="ExternalClassE4908D8C25DF4D1586D0A010BFBC5A53">3400</div>
    now we want only 3400 values i am using this code
    ring Descrption = rows["Description"].ToString();
    if (! string.IsNullOrEmpty(Descrption))
    char[] splitString = new char[] { '<', '>' };
    string[] parts = Descrption.Split(splitString,
    StringSplitOptions.RemoveEmptyEntries);
    // string[] Dec_1 = Dec.Split(new char[] { '<' }, StringSplitOptions.RemoveEmptyEntries);
    rows["Description"] = parts[1].ToString();

    Hope the below helps as start..Modify 
    //Option1
    Descrption = Descrption.Substring(0, Descrption.LastIndexOf("<"));
    Descrption = Descrption.Substring(Descrption.LastIndexOf(">") + 1);
    Console.WriteLine(" {0} ", Descrption);
    //Option2
    Console.WriteLine(" {0} ", Regex.Replace(Descrption, "<[^>]*>", string.Empty));
    accordingly..

  • How to split strings into columns

    Hi guys,
    I have a select like this:
    select 'testing1'||'.'||'testing2'||'.'||'testing3' from dualwhich gives me an output like this:
    testing1.testing2.testing3How can I split this into 3 columns in SQL PLUS?
    Thank you in advance

    user643734 wrote:
    Thank you guys for all your help.
    Hi,
    I tried to resolve your problem using somme functions...
    I know is a long, long story but it works.
    Regards,
    Ion--create table_pivot
    CREATE TABLE pivot_table(id VARCHAR2(1) primary key, all_concat VARCHAR2(1810));
    --add data
    insert into pivot_table (id, all_concat) values('x','12345.2829303132.234234.234234.234234');
    insert into pivot_table (id, all_concat) values('y','67890.2324252627.234234.234234.234234.332545');
    insert into pivot_table (id, all_concat) values('z','11121314.12345.234234.234234.234234.23432.32453245.345435.345435');
    insert into pivot_table (id, all_concat) values('a','151617.67890.234234.234234');
    insert into pivot_table (id, all_concat) values('b','1819202122.1112131415.234234.234234.234234.345435');
    insert into pivot_table (id, all_concat) values('c','2324252627');
    insert into pivot_table (id, all_concat) values('h','2829303132.234234.234234.234234.23432.32453245.345435.345435.4325435.345');
    insert into pivot_table (id, all_concat) values('r','');
    set termout off
    --procedures and functions to compile
    --1. Main function to format strings
    create or replace function fgetformatstring
    (v_max_rows numeric, v_crt_row varchar2, v_table_source varchar2, v_save_to_table varchar2, v_option numeric)
    return varchar2
    is
    v_crt_char      numeric:=0;
    v_pos_char      numeric:=1;
    v_count      numeric:=0;
    v_string_out varchar2(500);
    v_str_paded     varchar2(10):=',null';
    v_length_pad     numeric;
    v_diff_pad numeric;
    l_crt_row varchar2(1800);
    v_char char:=',';
    v_delimiter char:='.';
    l_save_to_table varchar2(1000);
    l_max_rows     numeric;
    begin
    l_crt_row:=replace(v_crt_row,'.' ,',');
    l_save_to_table:=v_save_to_table;
    l_max_rows:=v_max_rows;
    if v_option=0 then     --get the ',null' to paded in pivot_table     
    loop
              v_pos_char:=v_crt_char;
              v_crt_char:=instr(v_crt_row,v_char, v_crt_char+1);
              v_count:=v_count+1;
    exit when v_crt_char=0 or v_count=1000;
         end loop;
         v_string_out:=' ';
         v_count:=v_count-1;
         v_diff_pad :=l_max_rows-1-v_count;
    if v_diff_pad >0 then                    --nothing to add
         v_length_pad:=length(v_str_paded);-- (+v_char)
         v_length_pad:=v_diff_pad*v_length_pad;
         v_length_pad:=v_length_pad+1;
         v_string_out:=rpad(v_string_out,v_length_pad,v_str_paded);
    end if;
    end if;
    if v_option=1 then     --get definition of v_save_to_table
         v_count:=1;
         v_string_out:=' ';
         loop
    exit when v_count=l_max_rows+1 or v_count>=1000;
    v_length_pad:=length(v_string_out||'col'||to_char(v_count)||',');
              v_string_out:=rpad(v_string_out,v_length_pad,'col'||to_char(v_count)||',');
              v_count:=v_count+1;
         end loop;
    v_string_out:=trim(v_char from v_string_out);
              --v_string_out:='id,'||v_string_out;
              v_string_out:=v_string_out;
    end if;
    if v_option=2 then     --get position of last comma  
    loop
              v_pos_char:=v_crt_char;
              v_crt_char:=instr(v_crt_row,v_char, v_crt_char+1);
              v_count:=v_count+1;
    exit when v_crt_char=0 or v_count=1000;
         end loop;
         v_string_out:=substr(v_crt_row,1,v_pos_char-1);
    end if;
    if v_option=3 then     --get numbers of delimiters(.)
    loop
              v_pos_char:=v_crt_char;
              v_crt_char:=instr(v_crt_row,v_delimiter, v_crt_char+1);
    --dbms_output.put_line( 'Rows: ' ||v_crt_row|| ' iteration: '||v_count);
              v_count:=v_count+1;
    exit when v_crt_char=0 or v_count=1000;
         end loop;
         v_count:=v_count;
         v_string_out:=to_char(v_count);
    end if;
    if v_option=4 then     --get sql command to create v_save_to_table
         v_count:=1;
         v_string_out:=' ';
         loop
    exit when v_count=l_max_rows+1 or v_count>=1000;
    v_length_pad:=length(v_string_out||'col'||to_char(v_count)||' varchar2(40), ');
              v_string_out:=rpad(v_string_out,v_length_pad,'col'||to_char(v_count)||' varchar2(40), ');
              v_count:=v_count+1;
         end loop;
    v_string_out:=trim(' ' from v_string_out);
              v_string_out:=trim(v_char from v_string_out);
              v_string_out:='create table '|| l_save_to_table ||'('||v_string_out||')';
    end if;
    if v_option=5 then     --get numbers of delimiters(,) 
    loop
              v_pos_char:=v_crt_char;
              v_crt_char:=instr(v_crt_row,',', v_crt_char+1);
              v_count:=v_count+1;
    exit when v_crt_char=0 or v_count=1000;
         end loop;
         v_count:=v_count-1;
         v_string_out:=to_char(v_count);
    end if;
    dbms_output.put_line( 'string: ' ||v_string_out|| ' option: '||v_option);
    return v_string_out;
    end;
    --2.get max items
    create or replace function fgetmaxitems
    --get the max number of items founded in the pivot_table.all_concat
    --before change the points with comma
    return numeric
    is
    v_max                numeric:=0;
    v_field               pivot_table.all_concat%type;
    v_crt_max numeric:=0;
    v_crt_row     varchar(1000);
    cursor c1 is
    select all_concat from pivot_table;
    begin
    v_crt_max:=0;
    v_max:=0;
    open c1;
    loop
    fetch c1 into v_field;
    exit when c1%notfound;
    v_crt_row:=v_field;
    v_crt_max:=fgetformatstring(0,v_crt_row,'pivot_table','',3);
    if v_crt_max>v_max then
         v_max:=v_crt_max;
    end if;
    end loop;
    close c1;
    return v_max;
    end;
    --3. insert the rows in table_dest
    create or replace procedure pinsertrow
    v_max_rows numeric,
    v_all_concat varchar2,
    v_source_table_name varchar2,
    v_save_to_tablename varchar2
    is
    v_sql_string      varchar2(1000);
    l_all_concat     varchar2(1500);
    begin
    l_all_concat:=replace(v_all_concat,'.' ,',');
    v_sql_string:='('||l_all_concat||')';
    v_sql_string:=' insert into ' ||v_save_to_tablename
    ||' (' ||fgetformatstring(v_max_rows,l_all_concat,v_source_table_name,v_save_to_tablename,1)||')'||
    ' values'||v_sql_string ;
    execute immediate v_sql_string;
    end;
    --4.procedure to create dinamically <table_dest>
    create or replace procedure pcreatesavetable
    (v_table_source varchar2, v_save_to_table varchar2)
    is
    v_sql_string      varchar2(1000);
    already_exists exception;
    pragma exception_init(already_exists,-955);
    v_max numeric;
    begin
    --clear empty values;
    v_sql_string:='delete from ' ||v_table_source|| ' where length(all_concat)=0 or (all_concat) is null';
    execute immediate v_sql_string;
    v_sql_string:='';
    v_max:=fgetmaxitems;
         --create new table
         v_sql_string:=fgetformatstring(v_max,'all_concat', v_table_source,v_save_to_table,4);
    dbms_output.put_line( 'sql create : '|| v_sql_string);
    execute immediate v_sql_string;
    exception
         when already_exists then
    --delete old table
         v_sql_string:='drop table ' ||v_save_to_table;
         execute immediate v_sql_string;
         --create new table
         v_sql_string:=fgetformatstring(v_max,'all_concat', v_table_source,v_save_to_table,4);
    dbms_output.put_line( 'sql recreate final_table : '|| v_sql_string);
    execute immediate v_sql_string;
    end;
    --5.main procedure
    create or replace procedure pmainproc(v_save_to_table varchar2)
    is
    v_key_pivot      pivot_table.id%type;
    v_column_pivot     pivot_table.all_concat%type;
    v_max numeric;
    v_crt_row          varchar2(1600);
    cursor c2 is select y.id , y.all_concat
         from pivot_table y
    ;     --cursor upon pivot_table 
    begin
    v_max:=fgetmaxitems;
    if v_max <> 0 then
    --clear empty values;
    delete from pivot_table where length(all_concat)=0 or (all_concat) is null;
    --change all points with comma
    update
    (select x.id, x.all_concat from pivot_table x, pivot_table y where x.id=y.id) b
    set b.all_concat=replace(b.all_concat,'.', ',');
    -- padd the all_concat with ',null'
    update
    (select x.id, x.all_concat from pivot_table x, pivot_table y where x.id=y.id and
    fgetformatstring(v_max,x.all_concat,'pivot_table',v_save_to_table,5) <> v_max
    ) b
    set b.all_concat=b.all_concat || fgetformatstring(v_max,b.all_concat,'pivot_table',v_save_to_table,0);
    --remove last
    update pivot_table
    set all_concat= fgetformatstring(v_max,all_concat,'pivot_table',v_save_to_table,2)
    where fgetformatstring(v_max,all_concat,'pivot_table',v_save_to_table,5) = v_max;
    open c2;
    loop
    fetch c2 into      v_key_pivot, v_column_pivot;
    exit when c2%notfound;
    v_crt_row:=v_column_pivot;
    -- insert data in to final_table
    pinsertrow(v_max,v_crt_row,'pivot_table',v_save_to_table);
    end loop;
    close c2;
    end if;
    end;
    --create table_dest
    --the table_dest will be created automatically, so you need admin privilege to run that before compile pcreatesavetable :
    connect / as sysdba or connect system/password
    --grant create table to hr;
    --conne hr/hr;
    exec pcreatesavetable('pivot_table','table_dest');
    --add data to table_dest
    exec pmainproc('table_dest');
    set termout on
    select * from table_dest;
    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Function created.
    Function created.
    Procedure created.
    Procedure created.
    Procedure created.
    PL/SQL procedure successfully completed.
    PL/SQL procedure successfully completed.
    COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10
    12345 2829303132 234234 234234 234234
    67890 2324252627 234234 234234 234234 332545
    11121314 12345 234234 234234 234234 23432 32453245 345435 345435
    151617 67890 234234 234234
    1819202122 1112131415 234234 234234 234234 345435
    2324252627
    2829303132 234234 234234 234234 23432 32453245 345435 345435 4325435 345
    7 rows selected.

  • How to split strings in pl/sql

    PROCEDURE COLUMN_SPLIT (p_def   IN     VARCHAR2,
                                         p_sch          OUT VARCHAR2,
                                         p_table           OUT VARCHAR2,
                                         p_column          OUT VARCHAR2)
       IS
       BEGIN
          NULL;
       END;
    END;
    I want to split p_def by dots, check for 3 elements, and return them in p_sch, p_table and p_column
    for example p_sch will be like hello.howare.you.
    I want to split it to
    hello
    howare
    you
    I have very limited knowledge with pl/sql can someone point me in the right direction or maybe show some example.

    PROCEDURE COLUMN_SPLIT (p_def   IN     VARCHAR2,
                                         p_sch          OUT VARCHAR2,
                                         p_table           OUT VARCHAR2,
                                         p_column          OUT VARCHAR2)
       IS
       BEGIN
           p_sch    :=  REGEXP_SUBSTR(p_def, '[^.]+', 1, 1);
           p_table  :=  REGEXP_SUBSTR(p_def, '[^.]+', 1, 2);
           p_column := REGEXP_SUBSTR(p_def, '[^.]+', 1, 3);
       END;
    Ramin Hashimzade

  • How to split rows based on two columns..

    Hi all...
    I have a requirement.
    I have product column, sell, purchace prices..(total of three columns) in a data set.
    my data set is such a way that..if sale price exists...there is no purchase price and vice versa..
    I need too present in a report ,two tables:
    table 1 consists of only Sale price items
    table 2 should contain only Pruchase Items.
    Please see the below picture for clear understanding..
    Is that doable? Where do we need to impose a condition?I tried to impose a condition but,it didnt seem to work
    http://i51.tinypic.com/29xfdc6.jpg
    Please help.

    Can you send me the template and xml file to [email protected]? I can try to help.
    Did you try to filter out the records by the sale price or purchase price column not equal to null?
    Thanks,
    Bipuser

  • How to take all the prevoius until space or tab

    suppose i have the following
    Kim/Name 3 4 london/Place 5 33/age 10
    suppose i ask the user to enter a number then i'll retreive all the data before that number for example
    if the user enter 3 i'll return K im/Name
    if the user enter 10 i'll return 33/age
    Where there is 1space between the number and the words???

    it should be
    Kim/Name 3 london/Place 5 33/age 10
    class Test {
         public static void main(String[] args) {
              String data = "Kim/Name 3 london/Place 5 33/age 10";
              String lookingFor = "5";
              String regexp = "([^ /]+/[^ ]+) " + lookingFor;
              Matcher matcher = Pattern.compile(regexp).matcher(data);
              if (matcher.find()) {
                   System.out.println(matcher.group(1));
              } else {
                   System.out.println("No match");
    }Kaj

  • How can I save a Numbers spreadsheet as a tab delimited file?

    Okay, I would like to save a Numbers spreadsheet as a tab delimited file. But of course I can't do that, since Numbers only saves as a comma separated values file.
    Plan B: I can open up a CSV file created by Numbers in TextEdit, and I would like to Find and Replace all the commas with tabs. So I open up the Find window, enter a comma under Find, but of course when I put the cursor in the Replace blank and hit the Tab key, it just goes to the next blank instead of giving me a Tab.
    Is there a way I can get a Tab into that blank so I can replace all the commas with tabs?
    --Dave

    Hello
    When we use TextEdit as I described, rows are separated by Returns.
    It appears that your program requires LineFeeds.
    Here is a neat soluce.
    Save this script as an Application Bundle.
    --\[SCRIPT tsv2csv]
    (* copy to the clipboard a block of datas separated by tabs
    run the script
    You will get on the desktop a csv file named from the current date-time.
    The values separator is set to match the Bento's requirements:
    If the decimal separator is period, the script uses commas.
    If the decimal separator is comma, the script uses semi-colons.
    This may be changed thru the setting of the property maybeSemiColon.
    According to the property needLF,
    embedded Returns will be replaced by LineFeeds
    or
    embedded LineFeeds will be replaced by Returns
    Yvan KOENIG (Vallauris, FRANCE)
    le 10 octobre 2008
    property needLF : true
    (* true = replace Returns by LineFeeds
    false = replace LineFeeds by Returns *)
    property maybeSemicolon : true
    (* true = use semiColons if decimal separator is comma
    false = always uses commas *)
    --=====
    try
    set |données| to the clipboard as text
    on error
    error "the clipboard doesn't contain text datas !"
    end try
    set line_feed to ASCII character 10
    if |données| contains tab then
    if maybeSemicolon then
    if character 2 of (0.5 as text) is "," then
    set |données| to my remplace(|données|, tab, quote & ";" & quote)
    else
    set |données| to my remplace(|données|, tab, quote & "," & quote)
    end if -- character 2 of (0.5…
    else
    set |données| to my remplace(|données|, tab, quote & "," & quote)
    end if -- maybeSemiColon
    end if -- |données| contains tab
    if needLF then
    if |données| contains return then set |données| to my remplace(|données|, return, line_feed)
    set |données| to my remplace(|données|, line_feed, quote & line_feed & quote)
    else
    if |données| contains line_feed then set |données| to my remplace(|données|, line_feed, return)
    |données| to my remplace(|données|, return, quote & return & quote)
    end if -- needLF
    set |données| to quote & |données| & quote
    set p2d to path to desktop as text
    set nom to my remplace(((current date) as text) & ".csv", ":", "-") (* unique name *)
    tell application "System Events" to make new file at end of folder p2d with properties {name:nom}
    write |données| to file (p2d & nom)
    --=====
    on remplace(t, tid1, tid2)
    local l
    set AppleScript's text item delimiters to tid1
    set l to text items of t
    set AppleScript's text item delimiters to tid2
    set t to l as text
    set AppleScript's text item delimiters to ""
    return t
    end remplace
    --=====
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE vendredi 10 octobre 2008 13:47:36)

  • How to extract substring from a string based on the condition ??

    Hi,
    I'm having a very large string which as below
    EQD+CN+SAMPLE18767+2200+++5'
    NAD+CA+FIR:172:20'
    DGS+IMD+3.2+2346+55:CEL'
    FTX+AAA+++GOOD'
    FTX+AAA+++ONE'
    EQD+CN+SAMPLE18795+2200+++5'
    NAD+CA+TIR:172:20'
    DGS+IMD+3.2+2346+55:CEL'
    FTX+AAA+++SECOND'
    FTX+AAA+++IS FAIR'
    similarly FTX+AAA as above and it goes on
    i tokenized each segment with delimiter as ' and able to read each segment.
    Now i want to concatenate the FTX+AAA in a single segment if more than one FTX+AAA with IMMEDIATE below
    The output is as follows
    EQD+CN+SAMPLE18767+2200+++5'
    NAD+CA+FIR:172:20'
    DGS+IMD+3.2+2346+55:CEL'
    FTX+AAA+++GOOD,ONE'
    EQD+CN+SAMPLE18795+2200+++5'
    NAD+CA+TIR:172:20'
    DGS+IMD+3.2+2346+55:CEL'
    FTX+AAA+++SECOND,IS FAIR'
    similarly FTX+AAA should be concatenated if it has similar FTX+AAA IMMEDIATE below.
    The FTX+AAA segments can come any number of times immediate below
    Please help me how we can do this??? Can anyone help me with the code snippet to do this?
    Thanks,
    Kathir

    Encephalopathic wrote:
    You've posted > 300 times here and you still don't respect the rule regarding notification of all cross-posts? [http://www.java-forums.org/advanced-java/30061-how-extract-substring-string-based-condition.html]
    Do you think this this will help convince others to help you?See also [http://www.coderanch.com/t/500088/java/java/extract-substring-string-based-condition|http://www.coderanch.com/t/500088/java/java/extract-substring-string-based-condition].

Maybe you are looking for

  • How to delete null values in a table

    hi all, tell me please any one how to delete null values in a table example: in emp table is there empno ename job mgr sal deptno 7900 scott 7902 2000 10 7499 clerk 7900 20 7834 james manager 3000 30 like this in the above emp table there are some nu

  • PS elements saves pic as a blank file and I cannot open it

    Hey guys, I'm hoping you can help me. I am using Photoshop Elements 8 and I'm not sure what happened (or what I did), but suddenly the files I save (save-as, i rename retouched files) started saving as blank thumbnails. I cannot open them, and the pr

  • Why do I lose type effects

    Why do I lose type effects on my printed page such as emboss, bevel and drop shaodow (in Photoshop CS6) when I save my file as a jpeg or pdf?

  • Account names can break LDAP logins?

    I've successfully installed and patched (patches 118833-36, 119963-08 and 122032-05) my Solaris 10 system so it's using LDAP against the Sun Java System Directory Server Enterprise Edition 6.2. On my test box, I have several test accounts setup. On t

  • How can I synchronize IPTC Extension metadata in LR 5?

    All - The Copy and Synchronize Metada interfaces to LR 5 shows IPTC Extension (IPTC Image fields and others) metadata, however when I use these functions this information is not included. Is this a limitation or a bug? How can I get this to work? Kin