Splitting String and SubString in C#?

Hi, I have this string with names and their branches like this:
Label/Sublabel/SubLabel2/SubLabel3.
 Where the string  before "/" is a superlabel of its corresponding sublabel. 
--Label
--------Sublabel (sub label of Label)
-------------- SubLabel2 ( sub label of Sublabel)
---------------------SubLabel3 (sub label of Sublabel2)
....and so on.
I have two arrays Label and SubLabel namely. I want to put split values into these arrays as the following manner.
Label = All the super labels must enter this array.
Sublabel = all sublabels must enter this array.
Label nests Sublabel , Sublabel nests Sublabel2, Sublabel2 nests Sublabel3 and Sublabel3 probably will nest Sublabel4 and so on.  I need a way to find out which label is a Superlabel of its corresponding sublabel. A superLabel is a key to find out its
Sublabel.
so, far I have this code only to split the string.
string str = "Label/SubLabel/SubLabel2/SubLabel3";
string[] names = str.Split('/');
foreach (string name in names)
Console.WriteLine(name);
How do I put the split values into two separate arrays for Label and SubLabel ?

In your code you wanna put folder names into different arrays right?
string str = "Label/SubLabel/SubLabel2/SubLabel3";
string[] names = str.Split('/');
foreach (string name in names)
Console.WriteLine(name);
In this example there is 1 Label and 3 SubLabels, am I right?
string str = "Label/SubLabel/SubLabel2/SubLabel3";// List for Label List<string> labelList = new List<string>():// List for SubLabelList<string> subLabelList = new List<string>():
string[] names = str.Split('/');
foreach (string name in names)
Console.WriteLine(name); if(name.ToLower().Contains("sublabel") subLabelList.Add(name); else labelList.Add(name);
In the end you fill two List array with your label names. I think you are asking for that I do not misunderstand your question.

Similar Messages

  • String and substring from an array of string

    hello,
    I really need some help here, I have a input string coming in and an array of words coming from the table. I need to be able to find the exact matching string and its longest subtring. For example if my input is washington, the match will be washington which is at #1 in the table and there 2 bustrings of Washington in the table, shington and ington. So then my program will report the longest substring; which is shington.
    remember the program is reporting the exact match and the longest substring of the match.
    Thank you,
    Yaka.
    Attachments:
    substr.vi ‏10 KB
    substr.JPG ‏19 KB

    yaka wrote:
    Thanks a lot. By the way I am not a student. I am working on testing wifi stuffs and need to generate some test definition files....
    -Yaka
    For future reference you may want to state that in your original post. To be honest I didn't post a solution because I did get the impression this was a homework assignment. We do see that on a regular basis here on the forums.
    I'm curious, what type of WiFi testing are you doing? Most of my testing is focused on networking and network protocols.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Splitting string and eleminating middle of the string

    Hi,
    I have string '619 E SHIP CREEK AVE # 301', where this string I have to remove the 'AVE' and keepp the remaing in the value, any help would be greatly appreciated.
    Thanks,
    Gladson

    This one you can do with my "complex" solution :-)
    select x, substr(x, 1, instr(x,'AVE',-1)-1)||substr(x,instr(x,'AVE',-1)+4, 9999) new from x;
    X                             NEW
    619 E SHIP CREEK AVE # 301    619 E SHIP CREEK # 301
    619 E AVEBURY AVE # 301       619 E AVEBURY # 301

  • How to split intiger and string

    String str="abc1,ss10";
    String strArr[] = str.split(",");
    here i want to split string and intigers separatelly, for example 'abc1'
    i want to split this...i want to display only charecters.....
    plz help me

    You would probably need some kind of regular expression to do that. But it really isn't a JavaMail question, is it? You would get a much better answer if you posted the question in the Java Programming forum.

  • How to Split the string using Substr and instr using loop condition

    Hi every body,
    I have below requirement.
    I need to split the string and append with single quotes('') followed by , (comma) and reassign entire values into another variable. so that i can use it where clause of update statement
    for example I am reciveing value as follows
    ALN varchar2(2000):=(12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434);
    Note: In the above variable i see 8 transactions, where as in real scenario i donot how many transaction i may recive.
    after modification i need above transactions should in below format
    ALTR Varchar2(2000):=('12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434');
    kindly help how to use substr and instr in normal loop or for loop or while loop while modifying the above transactions.
    Please help me to sort out this issue.
    Many Thanks.
    Edited by: user627525 on Dec 15, 2011 11:49 AM

    Try this - may not be the best way but...:
    create or replace type myTableType as table of varchar2(255)
    declare
    v_array mytabletype;
    v_new_str varchar2(4000);
    function str2tbl
             (p_str   in varchar2,
              p_delim in varchar2 default '.')
             return      myTableType
        as
            l_str        long default p_str || p_delim;
             l_n        number;
             l_data     myTableType := myTabletype();
        begin
            loop
                l_n := instr( l_str, p_delim );
                exit when (nvl(l_n,0) = 0);
                l_data.extend;
                l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
                l_str := substr( l_str, l_n+length(p_delim) );
            end loop;
            return l_data;
       end;
    begin
      v_array := str2tbl ('12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434', ',');
          FOR i IN 1 .. v_array.COUNT LOOP
             v_new_str := v_new_str || ''''||v_array(i)||'''' || ',';
          END LOOP;
       dbms_output.put_line(RTRIM(v_new_str, ','));
    end;  
    OUTPUT:
    =======
    '12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434'HTH
    Edited by: user130038 on Dec 15, 2011 12:11 PM

  • Split string into two based on end of word and max length

    I have the following procedure, which is passed a comma separated string as it input, and it has to split it into two, and the split has to occur at the end of a word, and the first split part can't be more than 15 in length.
    Is there an more efficient way of achieving this? I have a loop in my main code that calls this procedure and in effect a nested loop has been created here.
    e.g. Hello, everyone, welcome, to, split, string' would be split into 'Hello' and 'everyone, welcome, to, split, string'
    create or replace procedure split_str
                   (pi_str  in  varchar2,
                    po_str1 out nocopy varchar2,
                    po_str2 out nocopy varchar2) is
      i number;
    begin
      if (len(pi_str) <= 15) then
        po_str1 := pi_str;
        po_str2 := NULL;
      else
        i := 1;
        loop
          exit when len(SUBSTR(pi_str, 1 ,INSTR(pi_str, ',', 1, i)-1)) > 15;
          po_str1 := SUBSTR(pi_str, 1 ,INSTR(pi_str, ',', 1, i)-1);
          po_str2 := SUBSTR(pi_str, INSTR(pi_str, ',', 1, i)+2);
          i := i+1;
        end loop;
      end if;
    end split_str; 

    You want to find the last space character before the 15th character.
    x := INSTR ( SUBSTR ( pi_str, 1, 15) , ' ' , -1)Then the first string is SUBSTR(pi_str,1,x) and the second string is SUBSTR(pi_str,x+1)

  • HELP URGENT:; Splitting strings in servlets

    hi ...
    I am trying to access the below servlet from another servlet in iplanet . I have to access a file and arrange the '|' delimited data in the file in a table format like in html ...
    I have used my own function inside the servlets which splits a string based on character ...But I always get
    Internal error: exception thrown from the servlet service function (uri=/servlet/ReportsDataServlet): java.lang.NullPointerException, Stack: java.lang.NullPointerException
    at ReportsDataServlet.split(ReportsDataServlet.java:82)
    at ReportsDataServlet.doPost(ReportsDataServlet.java:56)
    at ReportsDataServlet.doGet(ReportsDataServlet.java:14)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:919)
    at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:483)
    The sample code is shown below....I get the same error when i tries with stringokenizer as well....Pls help me fix this.....
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, Se
    rvletException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    cont=getServletContext();
    out.println("<html><head><title>Reports Data</title></head><body bgcolor=DBD0E2>");
    String repType = request.getParameter("Rep");
    String mon = request.getParameter("month");
    String day = request.getParameter("day");
    String year = request.getParameter("year");
    String repName = repType+"."+mon+"-"+day+"-"+year+".txt";
    BufferedReader in = new BufferedReader( new FileReader("/home/lnayar/baais/xmlServlet/"+rep
    Name));
    String st;
    st = in.readLine();
    cont.log(st);
    int c =0;
    out.println("<table border=\"3\" cellpadding=\"0\" cellspacing=\"0\" width=\"800\"><tr><td>L
    ATA</td><td>WC CLLI</td><td>WC NAME</td><td>ADSL_LOCATION</td><td>ATM FLAG</td><td>ATM RELIEF DATE</td><t
    d>FRAME FLAG</td><td>FRAME RELIEF DATE</td><td>GOLD FLAG</td><td>GOLD RELIEF DATE</td><td>OVERLAY INDICAT
    OR</td><td>COUNT</td></tr>");
    while (st != null)
    c++;
    st = in.readLine();
    StringTokenizer stt = new StringTokenizer(st);
    out.println("<tr>");
    while (stt.hasMoreTokens())
    //out.println("<td>"+stt.nextToken("|")+"</td>");
    out.println("<td>hello</td>");
    out.println("</tr>");
    while (st != null)
    c++;
    st = in.readLine();
    out.println("<tr>");
    Enumeration en = split(st,"|");
    while(en.hasMoreElements())
    out.println("<td>"+en.nextElement()+"</td>");
    out.println("</tr>");
    cont.log("out while");
    out.println("</table>");
    out.println("</body></html>");
    public Enumeration split (String str, String delim)
    Vector v = new Vector();
    int pos_1;
    int pos_2;
    //Set initial delimiter positions...
    pos_1 = 0;
    pos_2 = 0;
    //Start chopping off bits from the string
    //until left boundary reaches the length of string
    while ( pos_1 <= str.length() )
    pos_2 = str.indexOf(delim, pos_1);
    if ( pos_2 < 0 )
    pos_2 = str.length();
    String sub = str.substring (pos_1, pos_2);
    pos_1 = pos_2 + 1;
    v.addElement(sub);
    return v.elements();
    d deeply appreciate if soeone could take a look at the code and tell me exactly where i am going wrong ..... Its URGENT ...
    Thx
    klv

    But there is the while statement which filters null
    values..Which is useless in your case, because you proceed to change the value of st to something else which you don't check for null.
    At any rate, what you have to do is this:
    1. Look at the stack trace to find the line number where the error occurs.
    2. Look at that line in your code.
    3. Look at each object variable in that line. Find out how it became null and fix that.

  • Split string function in oracle ...

    Hello,
    Little question, is there any split string function available in Oracle.
    SQL> select more_info
    2 from dba_advisor_findings;
    MORE_INFO
    Allocated Space:4390912: Used Space:4237403: Reclaimable Space :153509:
    select more_info as Allocated_Space,
    more_info as Used_Space,
    more_info as Reclaimable_Space
    from dba_advisor_findings
    Allocated_Space Used_Space Reclaimable_Space
    4390912 4237403 153509
    Thanks,
    Manish Gupta

    I explored more on SUBSTR and INSTR string functions ... and below is the solution
    select substr(more_info,instr(more_info,':',1,1)+1,instr(more_info,':',1,2)-instr(more_info,':',1,1)-1) as "Allocated_Space",
    substr(more_info,instr(more_info,':',1,3)+1,instr(more_info,':',1,4)-instr(more_info,':',1,3)-1) as "Used_Space",
    substr(more_info,instr(more_info,':',1,5)+1,instr(more_info,':',1,6)-instr(more_info,':',1,5)-1) as "Reclaimable_Space"
    from dba_advisor_findings;
    Allocated_Space
    Used_Space
    Reclaimable_Space
    4390912
    4237403
    153509
    Thanks...

  • Split string into an array (Skip first character)

    I have a string like:
    ,open,close,open
    I want to parse the data into an array (without the first ','). I found and tweaked the following code, but the result was:
    +<blank line> (think this is coming from the first ',')+
    off
    on
    off
    FUNCTION SPLIT (p_in_string VARCHAR2, p_delim VARCHAR2) RETURN t_array
    IS
    i number :=0;
    pos number :=0;
    lv_str varchar2(50) := p_in_string;
    strings t_array;
    BEGIN
    -- determine first chuck of string
    pos := instr(lv_str,p_delim,1,1);
    -- while there are chunks left, loop
    WHILE ( pos != 0) LOOP
    -- increment counter
    i := i + 1;
    -- create array element for chuck of string
    strings(i) := substr(lv_str,1,pos-1);
    -- remove chunk from string
    lv_str := substr(lv_str,pos+1,length(lv_str));
    -- determine next chunk
    pos := instr(lv_str,p_delim,1,1);
    -- no last chunk, add to array
    IF pos = 0 THEN
    strings(i+1) := lv_str;
    END IF;
    END LOOP;
    -- return array
    RETURN strings;
    END SPLIT;
    I am working on a 9i database.

    How is your collection defined? Assuming you are doing something like
    SQL> create type t_array as table of varchar2(100);
      2  /
    Type created.then you would just need to add an LTRIM to the code that initializes LV_STR and add appropriate EXTEND calls when you want to extend the nested table
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace FUNCTION SPLIT (p_in_string VARCHAR2, p_delim VARCHAR2)
      2    RETURN t_array
      3  IS
      4    i number :=0;
      5    pos number :=0;
      6    lv_str varchar2(50) := ltrim(p_in_string,p_delim);
      7    strings t_array := t_array();
      8  BEGIN
      9    -- determine first chuck of string
    10    pos := instr(lv_str,p_delim,1,1);
    11    -- while there are chunks left, loop
    12    WHILE ( pos != 0)
    13    LOOP
    14      -- increment counter
    15      i := i + 1;
    16      -- create array element for chuck of string
    17      strings.extend;
    18      strings(i) := substr(lv_str,1,pos-1);
    19      -- remove chunk from string
    20      lv_str := substr(lv_str,pos+1,length(lv_str));
    21      -- determine next chunk
    22      pos := instr(lv_str,p_delim,1,1);
    23      -- no last chunk, add to array
    24      IF pos = 0
    25      THEN
    26        strings.extend;
    27        strings(i+1) := lv_str;
    28      END IF;
    29    END LOOP;
    30    -- return array
    31    RETURN strings;
    32* END SPLIT;
    SQL> /
    Function created.
    SQL> select split( ',a,b,c', ',' ) from dual;
    SPLIT(',A,B,C',',')
    T_ARRAY('a', 'b', 'c')If T_ARRAY is defined as an associative array, you wouldn't need to have the EXTEND calls but then you couldn't call the function from SQL.
    Justin

  • About Strings and Memory

    Let's look at a couple of examples of how a String might be created, and let's further assume that no other String objects exist in the "String constant pool"l:
    String s = "abc"; //   creates one String object and one
                      //   reference variable In this simple case, "abc" will go in the pool and s will refer to it.
       String s = new String("abc"); // creates two objects,
                                  // and one reference variable In this case, because we used the new keyword, Java will create a new String object
    in normal (nonpool) memory, and s will refer to it. In addition, the literal "abc" will
    be placed in the pool.
    My question is this:
    Then why did the sun developers created the 'public String(String str)' constructor even it uses an additional memory?

    Caarmel wrote:
    Let's look at a couple of examples of how a String might be created, and let's further assume that no other String objects exist in the "String constant pool"l:
    String s = "abc"; //   creates one String object and one
    //   reference variable In this simple case, "abc" will go in the pool and s will refer to it.Nope. Executing that line only assigns a reference to an already existing String into the variable. The constant was put into the pool when the class was loaded. So your initial assumption of no Strings in the constant pool is invalid.
       String s = new String("abc"); // creates two objects,
    // and one reference variable Nope. As above, it creates one object. The other already existed.
    Then why did the sun developers created the 'public String(String str)' constructor even it uses an additional memory?First, note that your question really has nothing at all to do with the constant pool. Your question is really "Why does the String(String) constructor exist, given that String is immutable, and given that we can just do s2 = s1?" That question applies even in complete absence of the constant pool.
    I wasn't there when they made the decision, so I can't tell you what their thinking was. I can tell you one case where it's useful, however.
    String s1 = some_very_long_string;
    String s2 = s1.substring(x, x + a_small_number);
    String s3 = new String(s1.substring(x, x + a_small_number);Both the s2 and s3 lines create new String objects. However, in the case of s2, the new object shares the same char array as the original, whereas in the s3 case, a new backing array of just the right size is created. If s1 is very large, AND if the substring we're extracting is very small, AND if the substring needs to live on significantly longer than the original, then without the explicit new String(), even though we only need a few characters and could get away with a very small char array, we end up stuck with a large char array that can't be GCed even when the original String is.
    So in this rather unlikely scenario, we can avoid wasting a bunch of memory that can't be GCed when we only need a small fraction of it.
    Or maybe the constructor came about in early versions, before other aspects of the language making it mostly useless were solidified, and then it was kept for backward compatibility.
    Or maybe they didn't really have a good reason and just figured it made sense to have a copy constructor.
    Or maybe the reasons that make it mostly redundant are implementation details, and they wanted to provide a copy constructor so that as Java evolved, if the implementation changed, the functionality would still be there.
    Or maybe none of the above.

  • Write to Serial Port without splitting string data

    Hi, all, thank you for your help in advance.
    Problem:
    I am trying to write to the serial port with VISA write module. Somehow the string I tried to send was splitted before it was sent. For example, if I want to send "127", it sends "7', "2", "1". I don't know if there's anyway to configure the module so that it sends out the whole string at once. I use the return count to indicate how many times it spits the data. So "127" now returns "3" (sent three times. I would like to have it to return "1" so that "127" was sent in whole).
    Project:
    I am working on an application where a DC motor is controlled by a controller talking to the PC's serial port. "127" stands for its maximum power. The controller devides the power into 128 steps. Therefore I need to input number from 0 to 127 to command the speed.
    Any help or suggestion will be appreciated!

    Thanks for the prompt replies.
    About Number/ASCII
    I am using the Atmega128-Controller Chip to read in the signals sent from the computer serial port. Then it sends signals to the motor controller. The Atmega chip reads the ASCII string and converts it to hexadecimal number, sending that number to the motor controller. I can program the Atmega chip so that it either translates the ASCII string into hex as mentioned or accepts as it is. Either way, I want it to read two byte information at once (00 to 7F).
    If the VISA serial write can send only one byte at a time, then I may have to program the chip so that it buffers the readings. I have tried using number/hex converter and number/string converter, either case, the fact that VISA Write spits one byte at a time hinders the programming. For example: I defined numbers 1 to 5 represents 20% to 100% power output with 20% increment Then I defined "10" as "90%" power, but it reads "1" "0" seperately, so the actual out put is "20%" then "0%".
    I used the example VI provided by NI : advanced serial write/read. For convenience, attached here. Not all modification I made is saved.

  • How to use string functions (substr or ltrim or replace)  in OLAP universe.

    cost element (0COSTELMNT) - 10 CHAR
    Controlling area (0CO_AREA) - 4 CHAR
    [0COSTELMNT].[LEVEL01].[[20COSTELMNT]].[Value]
    cOST ELEMENT is compounded/prefixed with Controlling Area. I just want to see cost element without conrolling area in the BO report.
    Currenlty BO unierse is build based on bex query. I am able to suppress the compounding object in bex query by chaning controlling area to 'No display'. But still BO Webi report displaying compounded values in the report. (Bex report works as expected)
    eg: Current display in reort.
    controlling area/cost element.
    AB00/2222
    AB00/2223
    AB00/2224
    Wanted like  below:
    2222
    2223
    2224
    I think by using string fucntions (substring, ltrim or  replace etc.), I can get the required result. But I am having issues with syntax. I have used like below.
    substr(0COSTELMNT ; 5 ; 10)
    substr(0COSTELMNT; 5 ; Length(0COSTELMNT)-5)
    substr(0COSTELMNT; Pos(0COSTELMNT;"/")+1;10)
    ltrim(0COSTELMNT,'AB00/')
    What is the syntax for substring/replace functions in OLAP universe. Technical name of cost element in OLAP  universe is [0COSTELMNT].[LEVEL01].[[20COSTELMNT]].[Value].
    I want to fix this at universe level not at report level as  i am using cost element in filter/variable section of the report. Please provide me syntax for above example.

    Hi,
    In fact SAP BW MDX supports limited string manipulation and only with NAME and UNIQUENAME attributes.
    Here are some samples that you can use in universes:
    MID([0COSTELMNT].currentmember.NAME,1,4)
    LEFT([0COSTELMNT].currentmember.NAME,2)
    RIGHT([0COSTELMNT].currentmember.NAME,3)
    MID([0COSTELMNT].currentmember.UNIQUENAME ,1,4)
    LEFT([0COSTELMNT].currentmember.UNIQUENAME ,2)
    RIGHT([0COSTELMNT].currentmember.UNIQUENAME ,3)
    Didier

  • ByteArray to String and String to ByteArray  error at readUTF from datainpu

    hi everybody this is my first post I hope I can find the help I need I have been doing some research and couldnt find the solution thanks in advanced
    The Objective:
    im building a client server application with java and I need to send a response from the server to the client via Socket
    so the response is like this : <Signal : ByteArray> where Signal is a String so the client can Identify the Type of response
    and the ByteArray is an Array of bytes containing the Information I need
    The Problem:
    I have an Array of bytes containing the info to send and I need to pass this byte[] to a String add some String that let me Identify the data in the client side then remove the identifier in the client side and convert the resulting String back to an array of bytes this doesnt work
    The Code:
    Server Side (Creating the Byte Array):
    public byte[] createData(){
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    DataOutputStream dos = new DataOutputStream(baos);               
                    dos.writeUTF(requestedFile.getName());
                    dos.flush();
                    byte[] data = baos.toByteArray();
                    return data;
    }Server Side (Converting the byte[] to String and Add some Identifier)
    byte[] data= createData(); //Obtain the data  in a byte[]
    String response = new String(data);  //Convert the Data to String
    String Identifier= "14"; // to identify in the client side the data received this will be removed later
    response = Identifier+response;  // add the identifier to the String
    sendToClient( response.getBytes() );  //obtain bytes from the complete Response and send them to clientClient Side ( Receive the response that is a byte array containing the identifier plus the info <Identifier : info> )
                int index=response.indexOf(":")+1;  //find the index of the : so i can delete the identifier
                response=response.substring(index); // delete the identifier
                byte[] data = response.getBytes(); // obtains the bytes for the info ONLY cause the string no longer has identif
                receiveData ( data ); // send the data to be read by this method Client Side (Receive the Info sent from the server and read it)
                public void receiveData ( byte[] data ) {
                   ByteArrayInputStream bais = new ByteArrayInputStream ( data );
                   DataInputStream dis= new DataInputStream ( bais );
                   setTotalSize ( dis.readUTF( ) ); // here is the error  it catches an EndOfFileException without read the info
                }im tried sending other values like long and int and i was able to read them but the problem is with the Strings at the ReadUTF()
    Im tried to be the most clear as possible please help me this is driving me nuts
    and I would really appreciatte all your comments thanks

    lemaniak wrote:
    The Objective:
    im building a client server application with java and I need to send a response from the server to the client via Socket
    so the response is like this : <Signal : ByteArray> where Signal is a String so the client can Identify the Type of response
    and the ByteArray is an Array of bytes containing the Information I need
    The Problem:
    I have an Array of bytes containing the info to send and I need to pass this byte[] to a String add some String that let me Identify the data in the client side then remove the identifier in the client side and convert the resulting String back to an array of bytes this doesnt workFirst of all, well done: a nicely explained problem. I wish more people were as clear as you.
    Second: I'm no expert on this stuff, so I may well be wrong, but I did note the following:
    1. I can't see anywhere where you're putting out the ":" to separate your signal.
    2. You seem to be doing an awful lot of conversions from Strings to bytes and vice-versa, but only your filename is specified as a UTF-8 conversion. Could you not do something like:
    dos.writeUTF("14:" + requestedFile.getName());or indeed, more generically
    dos.writeUTF(signal + ":" + messageBody);from inside a createMessage() method.
    3. You haven't included the sendToClient() code, but your createData() looks suspiciously like what I would put in a method like that.
    From what I understand, you usually want mirror-images of your streams at your sending and receiving ends, so if your client is expecting an DataInputStream wrapping a ByteArrayInputStream to be read via readUTF(), your server better be sending a ByteArrayOutputStream wrapped in a DataOutputStream created, in its entirety, by writeUTF().
    But after your UTF conversion, you're adding your signal and then using String.getBytes(), which uses the default character set, not UTF.
    HIH (and hope I'm right :-))
    Winston

  • Getting a character at a given index in a String and returing as a String

    Hello,
    How do I simply grab one character in a string and return it as a string? I saw the substring() method but it does not like when I invoke:
    String test = "abcd";
    test = test.substring(0,0);
    **Above produces a runetime error. ***I need something that does this:
    String test = "abcd"
    test.needtodo(0) returns String "a".
    test.needtodo(1) returns String "b".
    ETC.
    ---- Thanks for the help.

    Ok I used Kaj's method, but what I am trying to do still inst working properly. Here is what I am trying to do:
    public String stringToBinaryStringWithLeadingZeroz(String input) {
         String binaryString="";
         int sizeOf = input.length();
         for(int i=0; i < sizeOf; i++)
              int intRepresentation = Integer.parseInt(String.valueOf(input.charAt(i)), 16);
              binaryString += Integer.toBinaryString(intRepresentation);
         return binaryString;
    }I am trying to take in a String that is Hex and return a string that is binary with leading zeros.
    So if the input is: stringToBinaryStringWithLeadingZeroz("3");
    It should be returning 0011 but its still only returning 11. It shouldnt be returning 0011 though. I am passing each character indivudally into the method toBinaryString() which just returns the result and appends onto the result.
    ** SCRATCHING MY HEAD **

  • How to Break this String and put into a Table

    Hi all,
    Currently i working on the Reading of Csv file.THe Csv file wil be stored as BLOB in one table.
    The Format of the Csv file is
    EMPCODE :DATEOFBIRTH
    312089 ,12/01/1984
    321456 ,03/05/1980
    120212 ,04/08/1987
    312456 ,23/12/1977
    311110 ,12/04/1998
    323232 ,20/06/1990
    UPLOAD_BLOB
    column     Datatype
    UploadId Number
    File_details BLOB
    And i reading the BLOB in one procedure and i m getting the String as like this ---->
    "312089 ,12/01/1984
    321456 ,03/05/1980
    120212 ,04/08/1987
    312456 ,23/12/1977
    311110 ,12/04/1998
    323232 ,20/06/1990"
    I am Dont know how to Parse this String and put in table
    While 1<STRING.LENGTH
    LOOP
    EMPCODE=SUBSTRING();
    DATEOFBIRTH=SUBSTRING();
    INSERT INTO TABLE VALID_EMPCODE(EMPCODE,DATEOFBIRTH)VALUES(......);END LOOP
    VALID_EMPCODE
    EMPCODE VARCHAR2(30)
    DATEOFBIRTH VARCHAR2(15)
    Can any one tell me how to parse this whole string and break them

    Duplicate post
    How to Break this String and put into a Table

Maybe you are looking for

  • Mac keeps freezing since upgraded to yosemite

    since I have upgraded to Yosemite on my MacBook pro 2009 safari and chrome and many other apps that I try to run freeze and lock up the entire computer. If I wait eventually it will unfreeze. I have tried restarting several times. Could I have a viru

  • Error The file iTunes Library.itl cannot be read......help

    I still can not open iTunes, and I keep getting an error message that tells me that the file iTunes Library.itl cannot be read because it was created by a newer version of itunes. I am currently using version 7.5.0.20 Thanks in advance for any of you

  • Post revaluation to selected depreciation area for an asset

    Hi, We are using depreciation area '01' for posting to GL accounts and '02' for fiscal reporting. It turned out that couple of assets had wrong depreciation key specified for depreciation area '02', which resulted in wrong depreciation calculated for

  • Can't call mobile phone and landline

    I live in the US and I tried to call my friends in UK.  It showed "you are not authorized to call this number".  Why?  I've enough Skype credit, and I've already added my friend's mobile phone number in my contact list.  What's the problem?  Can you

  • Agent Dashboard Profile

    I am seeking information about the user profile that is named in the Agent Dashboard, and how these are set-up.  We are using CRM 4.0 Web Client.  This particular agent dashboard screen is located on the main default login page of the web client and