String manipulation

I am trying to read in a CSV file and then use the data contained in the CSV file to insert data into a database.
I am programming in C#
in order to do this I set up a StringReader object, open the file and read the file to the end into a string.
To retreive each individual line I do a:
string[] tokens = text.split('\n')
which successfully splits up the text string into the tokens array, inserting single strings into each element.
After this I try to repeat the procedure in order to retreive single values out of the tokens[index] strings so as to insert them into a database; herein my problem lies.
so I have a string that looks something like this in each token array element:
"a,b,c,d,e,f,g,h,i,etc"
I do virtually the same operation:
foreach(string s in tokens)
string parts[] = s.Split(',');
for(int i =0; i < parts.Length(); i++)
//insert values into database
The problem is here that splitting up each string into parts is giving me an empty array ... from what I understand it should give me an array of elements like so:
parts[0]: "a"
parts[1]: "b"
parts[2]: "c"
etc ...
any clues you could help me with would be greatly appreciated.
Lance

Have you looked at just using SQL Loader to load the data straight into the database? SQL Loader was born to do this sort of stuff.
- Mark
=======================================
Mark A. Williams
Oracle DBA
Author, Professional .NET Oracle Programming
http://www.apress.com/book/bookDisplay.html?bID=378

Similar Messages

  • String Manipulation in BI Publisher Report Paramater

    Hi,
    My Problem is that I am not able to do string manipulation on BI Publisher report Prameters.
    Actually I want to Show Deptno-Dname in Menu(LOV).and when I select Certain combination like '10-Accounting',and while passing the parameter:Dept I wanted to Cut the department no(10) using string manipulation functions provided by oracle in Data Model(Query) in where clause like (where deptno=to_number(substr(:Dept,1,2)).
    This query is working fine in other application like TOAD,But not giving results in BI Publisher Report.
    It's also not giving any error while saving or running the report.
    Please suggest any solution.

    even I tried the following query in data model..
    select DISTINCT EMP.EMPNO as EMPNO,
    EMP.ENAME as ENAME,
    EMP.JOB as JOB,
    DEPT.LOC as LOC
    from SCOTT.DEPT DEPT,
    SCOTT.EMP EMP
    where emp.DEPTNO=DEPT.deptno
    and DEPT.deptno=nvl(to_number(substr(:department,1,2)),DEPT.deptno)
    But the Parameter which I want to pass say Department('10-Accounting'),
    Still it is showing employees from all departments.

  • String manipulation in JSTL

    Hello All
    I'm a just a beginner and I'm need to write a web page that is totally based on JSTL. I found out that the standard java tab lib in JSTL doesnt really support string manipulation or regular expression like in perl.
    As such, I would like to know what are the different options (like adding servlets/javabeans/etc) can i add to my JSTL page so that i can perform complex string manipulation to a data entered by the user in the text box?
    Some of the operations that I wish to carry out on the data are:
    1. check if data contains certain characters, strings
    2. joining and spliting strings
    3. find length of the string
    4. find the position of certain character in a string
    5. check if string match certain pattern.
    and many more.
    Would greatly appreciate if you guys can help to provide some light.
    Regards
    Beginner....

    You might find MicroNova YUZU JSP tag library (http://sourceforge.net/projects/micronova-yuzu) useful, especially if you need to support both JSP 1.2 and 2.0. Hope this helps.

  • Using CharAt for String Manipulation

    Hi,
    I am new to Java and am taking a Java class. I am trying to put a social security number in "nnn-nn-nnnn" format where n is a digit 0-9. I don't know if it would work with the charAt method of the String class. Does anyone have any suggestions on how to implement this kind of manipulation.
    It would be greatly appreciated!
    Thanks,
    waggypup99

    You could just create a class for social security number.
    e.g.
    public class SSNum{
        private int _num;
        public SSNum(int number){
          _num = number;
          * take number in the form  nnn-nn-nnnn
        public SSNum(String number){
          StringTokenizer st = new StringTokenizer(number,"-");
          StringBuffer numStringB = new StringBuffer(st.nextToken());
          numStringB.append(st.nextToken());
          numStringB.append(st.nectToken());
         _num = Integer.parseInt(numStringB.toString());
       public String toString(){
          //left as fun exercise
    }

  • Most efficient way to do some string manipulation

    Greetings,
    I need to cleanse some data in a string by replacing unsafe characters with encoded equivalents. (FYI, this is for the purpose of transforming "unsafe" characters into encoded values as data inside an XML document).
    The following code accomplishes the task:
    Note that a string "currentValue" contains the data to be cleansed.
    A string, "encodedValue" contains the result.
      for (counter = 0; counter < currentValue.length(); counter++)
        addChar = (currentValue.substring(counter,counter+1));
        if (addChar.equals("<"))
          addChar = "#60;";
        if (addChar.equals(">"))
          addChar = "#62;";
        if (addChar.equals("="))
          addChar = "#61;";
        if (addChar.equals("\""))
          addChar = "#34;";
        if (addChar.equals("'"))
          addChar = "#39;";
        if (addChar.equals("'"))
          addChar = "#39;";
        if (addChar.equals("/"))
          addChar = "#47;";
        if (addChar.equals("\\"))
          addChar = "#92;";
        encodedValue += addChar;
      } // forI'm sure there is a way to make this more efficient. I'm not exactly "new" to java, but I am learning on my own with no formal training and often take a "brute force" approach with my initial effort.
    What would be the most efficient way to re-do the above?
    TIA,
    --Paul Galvin
    Integrated Systems & Services Group

    im a c++ programmer so im not totally up on these java classes either but...from a c++ stand point you might want to consider using the if else statment.
    by using if else, you only test the character until you find the actual "violating" character and skip the rest of the tests.
    also, you might trying using something to check for alphaNumeric cases first and use the continue keyword when you find one. since more of your characters are probably safe than unsafe you can skip all the ifs/if else statement and only do one test on the good characters. (i just looked for a way to test that and i didnt find one. c++ has a function that does that by checking the ascii number range. dont think that works in java. but maybe you can find one, it would reduce the number of tests probably.)
    happy hunting,
    txjump :)

  • Bank Reconciliation- String Manipulation

    Hi Gurus,
    My client using match format to reconcile.
    The Line 86 "Note to Payee " is having some additional information other than the reference no. i.e. the 12 character is required for posting, then there is "Space" and then there are some other characters, which are not used.
    We only need the first 12 character of the to match  with reference no.
    I understand that "Define Search String for Electronic Bank Statement" provides means to "take  only first 12" characters.
    How to define this? What should be in the Searching and Mapping??
    Thanks in advance

    Hi Periasamy,
      In your case, define the search string as:
    ^############( |$)
    The above will select 12 characters from the start of the field and will stop if a space comes or end of line comes.
    Then you need to use the dialog 'Search string use' and map this string to relevant bank accounts. Use Target Field as 'Check-/DME Reference-/Assignment Number'.
    -S.

  • String manipulation question (servlet)

    Hello,
    I have a problem replacing parts of a String with values from a HttpServletRequest.
    I have the following method:
    public String replaceVariables(String s, HttpServletRequest request) {
         Enumeration e = request.getParameterNames();
         Vector v = new Vector();
         while(e.hasMoreElements()) {
              v.add(e.nextElement());
         String paramName;
         ListIterator li = v.listIterator();
         while(li.hasNext()) {
              paramName = (String) li.next();
              if (s.indexOf("#" + paramName + "#") > -1) {
                   s = new String(new StringBuffer(s).replace(s.indexOf("#" + paramName + "#"), s.indexOf("#" + paramName + "#") + (("#" + paramName + "#").length()), request.getParameter(paramName).toString()));
         return s;
    }What I am trying to do here is read in a line of text (String s) along with a the htpp servlet request. Put the names of the request paramaters into Vector v.
    Next I try to check the String s for any part of the String that matches one of the parameter names surrounded by #'s. If there is a match then I replace the #string# with the value associated with it in the http servlet request.
    The trouble is, my code on ly replaces the very first variable then stops, I cannot see why it does not do the rest.
    I hope this makes sense to somebody, becuase it doesn't to me :-)
    Thanks for any advise or help

    Yep. I have just done a basic one for testing. The String I read in is:
    username = #username#, action = #action#, email = #email#
    And the html form information that is sent to the servlet is:
    <input type="hidden" name="action" value="test">
    <input type="hidden" name="username" value="testuser">
    <input type="hidden" name="email" value="testemail">
    ....etc.
    I don't know if it makes a difference, I don;t think it does, but I am reading in a whole file, and passing the file line by line to this method.
    The method that passes each line is:
    public Vector generateHTML(HttpServletRequest request) {
         Vector v = new Vector();
         try {
              File f = new File("/fakepath/" + request.getParameter("action") + ".template");
              FileReader fr = new FileReader(f);
              BufferedReader br = new BufferedReader(fr);
              String s;
              while((s = br.readLine()) != null) {
                   s = replaceVariables(s, request);
                   v.add(s);
         } catch (Exception e) {
              // ignore
         } finally {
              return v;
    }

  • Advanced String Manipulation Using REGEXP

    Hello all,
    I've been trying to split a string using either REGEXP_SUBSTR and REGEXP_REPLACE functions with much success so I wonder whether anyone here can give me a hand. Basically the string I want to split in to 3 is in this format:
    'instanceno;partno;serialno'
    I have read numerous articles within last few days but I still can't get it to working (I'm sure due to my lack of regular expression handling knowledge in OBIEE). I found two articles discussing similar scenarios. One in here and the other one is here. Both of those are good, but I cannot apply those principles to my query as I'm keep getting issues with the use of semicolon (;).
    Could someone explain to me how to split this string so I can have 3 separate columns, please?
    Thanks and regards,

    Hi Anuhas,
    you have to create 3 columns in the report on 3 attribute columns inside le Logical Model with this syntax for the the string str = 'instanceno;partno;serialno'
    COLUMN1 = evaluate('regexp_substr(%1,''[^\;]+'', 1,1)',REPLACE(*str*,';','\;'))
    COLUMN2 = evaluate('regexp_substr(%1,''[^\;]+'', 1,2)',REPLACE(*str*,';','\;'))
    COLUMN3 = evaluate('regexp_substr(%1,''[^\;]+'', 1,3)',REPLACE(*str*,';','\;'))
    You have to use the REPLACE function (; --> \;) because the ; is e special character
    In this way you have:
    COLUMN1 = instanceno
    COLUMN2 = partno
    COLUMN3 = serialno
    The regex_substr(a,b,c) contains:
    a = str the string
    b = [^\;]+ find for the beginning of the string the character ;
    c = number of occurrence
    I hope it hepls.
    Regards,
    Gianluca

  • Can anyone help with string manipulation please?

    I am trying to change this string 43180-1-0001-37 into the following expression 43181-0001-37
    It is a string for Project No + Job Phase + Drawing No + Item No.
    The reduction of '43180' to '4318' is causing me the problem, I have the concatenation.
    Current report code is
    SELECT Os.[Orderno-o] As 'Order Number'
    ,Ph.PH_PHASE_NO + '.' + Re.REQUISITION_NUMBER As 'Req. Number'
    ,Pl.ID As 'Item ID'
    ,@CurrentProjectNumber + '-' + Ph.PH_PHASE_NO + '-' + Dr.DRAWING_NO + '-' + Cast(Pl.ITEM_NO As varchar(max)) As 'Drg & Item No.'
    It is this line giving me the problem?
    ,@CurrentProjectNumber + '-' + Ph.PH_PHASE_NO + '-' + Dr.DRAWING_NO + '-' + Cast(Pl.ITEM_NO As varchar(max)) As 'Drg & Item No.'

    Hi uh... Mr. Rubbish at SQL :)
    Unfortunately, there are many elements in your questions which aren't clear:
    1. What is the content in your columns PH_PHASE_NO, DRAWING_NO, ITEM_NO and what is their data type?
    2. What is the content of the variable @CurrentProjectNumber and what is its data type?
    3. It's unclear what is the logic behind the "reduction" of '43180' to '4318'. Do you want to remove trailing zeros? Shorten the value by one character? Because from what I see in your first sentence, it seems like you simply want to add 1 to '43180'
    and turn it into '43181'. That's a simple +1 operation. I also notice that you want to remove the "Job Phase" part from the string (which is "1" in your case)? Or do you need to add its value to the "Project No" (43180)? It's
    all quite confusing.
    Clarification would be highly appreciated.
    I would suggest, if you can, to please explain what you need NOT by specific examples, but by explaining your requirements IN GENERAL. In other words, don't use specific values like '43180', but start with a variable like 'X', and then let us know specifically
    what operation you want to perform on it (e.g. 'add 1' / 'remove trailing zeros' / 'shorten by one character' / 'add to it the value of some column' etc.). This will make it easier to understand the algorithm needed.
    Eitan Blumin; SQL Server Consultant - Madeira Data Solutions;

  • PAS string manipulation operations

    Hi
    How can I manipulate a string in PAS by replacing a character with another character?
    Thanks.

    Hi,
    Do you mean passing a string variable into a procedure or logic set?
    I think there is a "Text Variable" available in PAS which you can try using.
    Regards,
    Prasanth.

  • Simple Stream/String Manipulation

    I have a data stream that I am feeding into a method as a string, connects to a DB2 database and inserts the values contained in the string. Here is what the string looks like:
    ==SS39939294==
    03012|39|33|32|2|232|9995
    0333|34|007|32|2|7|95345
    0392|39|33|32|2|232|9995
    04492|39|3|32|8|77|95175
    0392|39|33|6|2|232|554I need to "trim" out the stamp (==SS39939294==), which represents the Unix time of the stream. I believe i will need to use the replaceAll method of the String class with a regular expression, but i'm not quite sure how to do that. Can anyone help?
    Thank you!

    Thank you both!
    I tried to read each line individually and filter them accordingly, but, no luck. Here is most of the code from method run():
              while (true) {
                   if (listenPort == null) {
                        logIt("listenPort is null");
                        return;
                   try {
                        clientConn = listenPort.accept();
                        clientHost = clientConn.getInetAddress().getHostName();
                        logIt("client connection accepted");
                        BufferedReader myRcv = new BufferedReader (
                             new InputStreamReader(clientConn.getInputStream()));
                        timeout = Integer.parseInt(
                                       System.getProperty("noDataTO", TIMEOUT));
                        clientConn.setSoTimeout(timeout*1000);
                        //boolean eof = false;
                        //while (!eof) {
                             //String rcvLine = myRcv.readLine();
                             //if (rcvLine != null){
                                            //long e__tm = Long.parseLong(rcvLine.substring(5,9));
                                            //SockServer.j_Insertion(rcvLine);
                             //else {
                             //     eof = true;
                                    String line;
                                    while ( (line = myRcv.readLine() ) != null )
                                    if (! line.startsWith("=="));
                                            SockServer.j_Insertion(line);
                        logIt("connection dropped by client");
                        clientHost = null;
                        logIt("listening on port: " + portArg);
                   } catch (InterruptedIOException ioe) {
                        logIt("IO ERROR: (cliento) " + ioe.getMessage());
                        logIt("restarting...");
                   } catch (IOException ioe) {
                        logIt("IO ERROR: (client) " + ioe.getMessage());
                        logIt("exiting...");
                        System.exit(1);
                   } finally {
                        try {
                             clientConn.close();
                        } catch (IOException ioe) {
                             logIt("ERROR: clientConn.close() failed - "
                                        + ioe.getMessage());
                             logIt("exiting...");
                             System.exit(1);
         }Obviously I pass the string to the j_Insertion method and println().
    The stream still comes through with the leading timestamp (as well as a ==START== and ==END== tags, which i was able to remove via replace before)
    Thanks!

  • Question about string manipulation

    Hello, I am practicing with Java and trying to learn it, and have a quick question. I am trying to get the count on a string of numbers for after a decimal point. the numbers are generated as the result of a math, so I can't use index, since the location of the decimal changes based on the number imputed. I want to figure this out on my own, but have hit a wall here, i've spent the past few hours trying every string command I can think of, and haven't figured it out yet, anyone mind pointing me in the right direction for which string to use? Thanks in advance for any help you can provide!

    Is this what you want?
    public class Fallen{
      public static void main(String[] args){
        String number = "123.45678";
        String frac = number.substring(number.indexOf('.') + 1);
        System.out.println(frac + " length=" + frac.length());
        frac = number.replaceFirst("^.+\\.", "");
        System.out.println(frac + " length=" + frac.length());
    }

  • Why is the problem? String Manipulation. Help Please.

    Ok I have two while loops that run with two different String arrays. The problem that I have is that I have a String LeadPI that looks like this: "Dr. Ayusman Sen, Pennsylvania State University".
    I would like to separate the String where the first half "Dr. Ayusman Sen" = String investigator; and "Pennsylvania State University" = String institution;
    basically separate the string into two separate String variables.
    can I do this in 1 while loop, and why is my output not functioning correctly?
    Lead PI: Dr. Ayusman Sen, Pennsylvania State University //*** String to manipulate***//
    // what the output should look like.
    Institution: Pennsylvania State University //*** this should be institution ***//
    Investigator: Dr. Ayusman Sen //*** this should be investigator ***//
    // This is the current output!
    Institution: Dr. Ayusman Sen
    Institution: Pennsylvania State University //*** this should be institution ***//
    Investigator: Dr. Ayusman Sen //*** this should be investigator. ***//
    Investigator: Pennsylvania State University
    Investigator: Dr. Ayusman Sen
    Investigator: Pennsylvania State University            
                 //********************** institution **************************//
                int count= 0;
                char separator =',';
                int index =0;
                do
                   ++count;
                   ++index;
                   index = LeadPI.indexOf(separator, index);
                while (index != -1);                       
                String[] insti = new String[count];
                index=0;
                int endIndex = 0;
                for(int i = 0; i < count; i++)
                    endIndex = LeadPI.indexOf(separator, index);
                    if(endIndex == -1)
                        insti= LeadPI.substring(index);
    else
    insti[i] = LeadPI.substring(index, endIndex);
    index = endIndex + 1;
    for(int i = 0; i < insti.length; i++)
    System.out.println("\tInvestigator: "+insti[i]);
    //********************** investigator **************************//
    index =0;
    do
    ++count;
    ++index;
    index = LeadPI.indexOf(separator, index);
    while (index != -1);
    String[] investi = new String[count];
    index=0;
    endIndex = 0;
    for(int i = 0; i < count; i++)
    endIndex = LeadPI.indexOf(separator, index);
    if(endIndex == -1)
    investi[i]= LeadPI.substring(index);
    else
    investi[i] = LeadPI.substring(index, endIndex);
    index = endIndex + 1;
    for(int i = 0; i < investi.length; i++)
    System.out.println("\tInstitution: "+investi[i]);

    Cheers!
    One of the problems with the String's split method is that it will nto handle the spaces properly. You will still need to trim it.
    In the class, below, I have coded for you two methods that will do what you are asking for.
    The first method (split) uses the String's split method, but then has to go through and trim down the strings to remove the space after the comma.
    The second method, tokenize, does the same thing, but uses a string tokenizer.
    Both work - I was just trying to illustrate both methods. The tokenizer method is about three times faster than the split method (in my tests) - but the split method is a little cleaner (IMHO) - but we're talking sub-millisecond differences in one execution.
    You would get the name from the [0] index of the returned String array and the institution from the [1] index, like so:
    System.out.println( "Name: " + info[ 0 ] );
    System.out.println( "Institution: " + info[ 1 ] );There are some issues with this code... if there is a comma in the institution name or the person's name, if messes things up - if, for example, the persons' name is "Paul Leska, Jr." - the routine splits the string in between Leska and Jr.
    The same thing happens in the institution name - if, for example, the name of the place is "University of Minnesota, Duluth" - we tokenize or split between Minnesota and Duluth.
    You'll either need to (1) watch your data, (2) make these routines smarter or (3) Change your input to already be split (from the source, perhaps).
    Here's the code:
    import java.util.StringTokenizer;
    public class Splitter {
      public static String[] split( String s, char c ) {
        String[] chopped = s.split(String.valueOf( c ));
        for( int idx = 0; idx < chopped.length; idx++ ) {
          chopped[ idx ] = chopped[ idx ].trim();
        return chopped;
      public static String[] tokenize( String s, char c ) {
        StringTokenizer st = new StringTokenizer( s, String.valueOf( c ) );
        int count = st.countTokens();
        String[] chopped = new String[ count ];
        for( int idx = 0; idx < count; idx++ ) {
          chopped[ idx ] = st.nextToken().trim();
        return chopped;
      public static void main( String[] args ) {
        String[] info = tokenize( "Michael A. Riecken, Jumping Mouse Software", ',' );
        for( int idx = 0; idx < info.length; idx++ ) {
          System.out.println( info[idx] );
        info = split( "Michael A. Riecken, Jumping Mouse Software", ',' );
        for( int idx = 0; idx < info.length; idx++ ) {
          System.out.println( info[idx] );
    }

  • String Manipulation in JSP

    Gidday All,
    I am converting an application from PHP to JSP
    in PHP I am able to explode a strings parts into an array.
    For example
    my string = "1.21.32.45.232";
    I want jsp to return an array containing the parts of this string separated by dots into an array.
    Any help appreciated.
    Thank You
    Colin

    Thanks everyone for your help,
    I knocked this up but don't get any output?
    Any help appreciated.
    Thank You
    Colin
    <html>
    <head>
    </head>
    <%@ page language="java" import="java.util.StringTokenizer" %>
    <body>
    <%
    StringTokenizer st = new StringTokenizer("123.21.56.23", ".");
    while ( st.hasMoreTokens() ){
    System.out.println( st.nextToken() );
    %>
    </body>
    </html>

  • A fairly simple string manipulation, I think!

    Hi, would be most grateful for some help on the following as
    getting close, but can't quite master it.
    I have thousands of records in one field in a sql 2000
    database in the following format
    racehorsename odds-odds-odds (country) i.e Stravinsky 3-9-7
    (USA)
    Basically I want to move the country from the end of the
    string to in between horesname and odds
    so result on above would look like Stravinsky (USA) 3-9-7
    A few point to note
    The odds can either be in "x-x" or "x-x-x" format or a not
    present (in which case no action required)
    County maybe a variation from 3 or 2 digits i.e (USA) or (UK)
    or not present at all in whihc case no action required
    many thanks
    Oli

    there may be a more elegant solution (probably involving
    regex), but assuming there's little to no variance in the syntax,
    use list functions with a space as a delimiter.
    <cfset foo = "Stravinsky 3-9-7 (USA)" />
    <cfset newfoo = listFirst(foo, ' ') & listLast(foo, '
    ') & listGetAt(foo, 2, ' ') />
    odds being x-x or x-x-x wouldn't matter. length of country
    abbreviation wouldn't matter. all that would matter would be the
    inclusion of additional spaces (like if the horse name has a space
    in it).

Maybe you are looking for

  • Are you 100% sure I'm losing Showtime through no fault of my own tonight at midnight?

    And if so what happens then? Does my U-450 bill go down? Does EPIX replace Showtime in the U-300 and U-450 packages? Does it really do any good to call and curse someone out on the phone? Or is just switching providers my best option? I know some of

  • Booting problems on macbook pro 17 inch

    So I have installed a new SSD Harddrive and ram, in my old macbook pro 17 inch. I have tried to get it to boot into "boot manager" by pressing Command + R, but nothing happens. I have tried this by the keyboard on the computer itself, a wired keyboar

  • How to include vi dependencies in application builder?

    I have a small project in which I am trying to build an application.  I am having issues with the build including all dependencies.  In the project explorer "Items" tab, there are 7 files listed (1 dll and 6 vi's).  When I build the application, and

  • A question regarding the limitations of using MS Access.

    Hello everyone, my question is not one of a direct comparison between Access, SQL Server and mySQL, but is concerned with how much of JDBC 2.0's functionality I can implement using an Access 2000 database and a type 1 driver. Are there area's of JDBC

  • New to SAP PLM7.0 integration with DMS

    Hi Friends, i am new to SAP Solution PLM7.0, and also about the integration with DMS. i wish to learn about this, so pls assist me and forward some links and documents. that would be helpfull for me. thanks, udhayasurian