Public String[] split(String regex)

How to change a Logical Operator "|" in regex expression to be treated as a regular character?
Example:
public class Temp {
public static void main (String[] b) {
String s = "zero|one|two";
String mac[] = s.split("|");
System.out.print(mac[2]); //"e" is printed
Replace "|" with "@" and you will get "two" as output.

thank you for a quick answer!
I've changed the line to:
String mac[] = s.split("\|");
but i get an error message:
Temp.java:4: illegal escape character
String mac[] = s.split("\|");
^
1 error

Similar Messages

  • String.class without split(String regex)

    hello,
    This is my problem:
    I am using eclipse with j2sdk1.4.2 which
    implement
    the clase String.class with
    method replaceAll(String regex, String replacement) and
    method split(String regex)
    PAth: home_j2sdk1.4.2/jre/lib/rt.jar 25.762kb
    In this way:
    String columns[] = line.split("\t");
    for (int i=0; i<columns.length; i++)
    ws.addCell(new Label(i,row,columns.replaceAll("\"","")));
    I move the code above to websphere Application Developer 5.1.2
    which use Home_Websphere/eclipse/jre/lib/rt.jar 8.827 kb
    this jar in yours String.class not contains the
    method replaceAll(String regex, String replacement) and
    method split(String regex)
    I need to find the use my code above with that methods,
    what i need to do ???
    possible,i need to find the source to String.java of j2sdk1.4.2
    which implement the methods, but where ???
    or there is another way to do it ???
    Any help is greatly appreciated.

    If websphere is supposedly 1.4 compatible, arethey
    "allowed" to leave out methods from the JFC? Not sure what the JFC is, but no, they would not be
    allowed to leave out any methods.
    JFC - Java Foundation Classes. I think they started calling what might be considered the Java Core the JFC when they first added Swing to the distribution. Maybe the term is no longer used.
    RRD-R      
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Difference between public void, private void and public string

    Hi everyone,
    My 1st question is how do you know when to use public void, private void and public string? I am mightily cofuse with this.
    2ndly, Can anybody explain to me on following code snippet:
    Traceback B0;//the starting point  of Traceback
    // Traceback objects
    abstract class Traceback {
      int i, j;                     // absolute coordinates
    // Traceback2 objects for simple gap costs
    class Traceback2 extends Traceback {
      public Traceback2(int i, int j)
      { this.i = i; this.j = j; }
    }And using the code above is the following allowed:
    B[0] = new Traceback2(i-1, 0);
    Any replies much appreciated. Thank you.

    1)
    public and private are access modifiers,
    void and String return type declarations.
    2)
    It's called "inheritance", and "bad design" as well.
    You should read the tutorials, you know?

  • Limitations of public string declarations

    Is there anylimit for declaring number of public string in a java file.
    I have declared some 3300 Public String in a .java file as shown below
    public class JbnIntlLabel implements Serializable {
    public Properties prop = new Properties();
    //start of new 2 series labels
    public String Text_2A= null;
    public String securityname_2A = null;
    public String eqtTool_2A = null;
    3300 such declarations.
    once i try to create a extra string and trying to compile..,its giving the below error
    /devusr8/web61/WebLogicServer/weblogic61/config/NewWeb61Domain/applications/demo/WEB
    -INF/src/com/apollo/services/bean > demo.sh JbnIntlLabel.java
    An exception has occurred in the compiler (1.3.1-rc2). Please file a bug at the Java Devel
    oper Connection (http://java.sun.com/cgi-bin/bugreport.cgi). Include your program and the
    following diagnostic in your report. Thank you.
    java.lang.StackOverflowError
    at com.sun.tools.javac.v8.code.ClassWriter.writeFields(ClassWriter.java:588)
    at
    Can anybody help me out..
    Thanks and regards
    vijay
    Tata Consultancy Services.
    Mumbai -India

    Is there anylimit for declaring number of public
    string in a java file.
    I have declared some 3300 Public String in a .java
    file as shown below
    public class JbnIntlLabel implements Serializable {
    public Properties prop = new Properties();
    //start of new 2 series labels
    public String Text_2A= null;
    public String securityname_2A = null;
    public String eqtTool_2A = null;
    3300 such declarations.
    once i try to create a extra string and trying to
    compile..,its giving the below errorThese are member variables.
    The Java language (Java Language Specification) does not limit them.
    The JVM however does (Java Vitual Machine Specification.) However you are no where close to that limit.
    (Note that I do not consider this a great design. Unless you have profiled this under load I would simply keep the values in a hash table and use a named argument to retrieve each value.)
    >
    /devusr8/web61/WebLogicServer/weblogic61/config/NewWeb6
    Domain/applications/demo/WEB
    -INF/src/com/apollo/services/bean > demo.sh
    JbnIntlLabel.java
    An exception has occurred in the compiler (1.3.1-rc2).
    Please file a bug at the Java Devel
    oper Connection
    (http://java.sun.com/cgi-bin/bugreport.cgi). Include
    your program and the
    following diagnostic in your report. Thank you.
    java.lang.StackOverflowError
    at
    com.sun.tools.javac.v8.code.ClassWriter.writeFields(Cla
    sWriter.java:588)As pointed out this is a compile time error. When you deploy something to a container it needs to create wrappers to support it.
    So it compiles code. And the compiler is most likely written in java. So I would guess that your container server needs to have its stack space increased. This might be the server itself or it might be a property within the server depending on how it actually works. (And I have no idea which it would be.)

  • Using split and regex

    I have a string like this:
    String parseMe = "//element//elementAgain/elementSecond"
    I want to get the string between // and /. How can I do that using split and regex? I'm confused on how will i construct my regex expression. can anyone help me or show me how? thanks!

            String parseMe = "//element//elementAgain/elementSecond";
            Pattern p = Pattern.compile("//(.*?)(?=/)");
            for(Matcher m = p.matcher(parseMe); m.find(); System.out.println(m.group(1)));

  • Possible to capture the delimiter with split(String, regex)?

    If StringTokenizer is frowned on, is it possilble to capture the delimiter in the string array when using split()?

    In Perl, all you have to do is put parentheses around the regex to have the delimiters returned as tokens. I can understand why the Sun devs left that feature out, though: it would make split's behavior twice as confusing as it already is. Anyway, I can't think of a better way to do it than your lookaround method, Sabre.
    If StringTokenizer is frowned on,
    Says who?Says the docs, actually. They say to use split() instead, as if it were a drop-in replacement for StringTokenizer. Then they confuse people even more by implying that split("\\s") is equivalent to the default behavior of StringTokenizer (it should be split("\\s+")). I submitted a bug report about that, but they didn't want to hear it.

  • String regex format

    I am stuck....trying to get the input numbers "1" and "0.23" into a string format result as "1:23",but instead I get a result of "1:0.23". getting rid of the "0." from the fractional number....
    it must be my regex expression, can this be manipulated using regex without using extra functions? appreciate all the help this forum has given.... 

    apok wrote:
    RavensFan wrote:
    I don't see where you are using a regex.  I see you using a format into string.
    Why don't you just multiply the second number by 100 and format that into the string as %0.f;%0.f  ?
    well...the string format is time based. Meaning if the fraction is less than 10, I need the "09" (width of 2) to be inplace and not "9" for the seconds. You made a good point in my use of a format function, when I wanted a regex function?
    I don't know which you actually want, I'm just commenting on what you are actually using versus what you say you are using.
    If the two values are integers, then I would use %d as the format specifier.  If you want it to be a width of 2 padded with zeroes, then it would be %02d.  So I think you actually want "%d:%02d" as your format specifier.  But you can work all that out if you right click the Format into String function and pick Edit Format String.

  • [JS - CS4] Help w/ JS choking on quotes in strings & regex

    Does anyone have an easy way to extract text from a string with quotes in JavaScript? I seem to have run into a few limitations in the implementation of javascript's regex and how a script handles a string with quotes in it.
    Here's what I'm working with: a regular string like:
    {appliedParagraphStyle:"Headline 6", changeConditionsMode:1919250519}
    from which I'd like to extract just the text 'Headline 6' without any quotes
    I came across a regex that would get just the text without the quotes, but apparently Javascript does not support lookbacks. For instance, Jongware's wonderful WhatTheGrep script can decode this regex:
    (?<=")[^"]*?(?=")
    but ID finds nothing with it when run in a GREP search. The same search without the lookback finds stuff:
    "[^"]*?(?=")
    but what it finds still has the quote at the start of the string.
    I thought I could just use substrings to extract the text without the quote, but apparently this has issues. See these examples from the Javascript console:
    testStr;
    Result: "Headline 6"
    testStr.length;
    Result: 1
    testStr;
    Result: Headline 6
    testHL.length;
    Result: 10
    testHL;
    Result: "Headline 6
    testHL.length;
    Result: 1
    So if the string has a quote mark in it, it doesn't return the true length, so I can't code a start and end of the string to extract the part without the quote.
    Do any of you more experienced folks have some magic insight? TIA!

    It's an InDesign Oddity.
    Double quotes inside GREP strings behave a bit strange. Usually, the " character will find any sort of double quote -- straight, curly open, and curly closed. But inside a GREP lookbehind string this suddenly fails (in a lookahead it seems to work fine).
    If you replace it with its "forced" variant ~{ it will work on open curly quotes:
    (?<=~{)[^"]*?(?=")
    and if you need it to work on the 'any kind of double quotes' you can even use this:
    (?<=["])[^"]*?(?=")
    But ... all of the above only applies to searching in InDesign! And that's what WhatTheGrep reports upon.
    GREP-inside-Javascript has nothing to do with InDesign's implementation -- it's part of Javascript itself, and it is a completely different thing. (Well, it's still GREP of course. But there is no such thing as "It's still GREP" -- there are lots of different implementations.)
    So it's perfectly possible that this expression works in InDesign but does not work inside Javascript, when applied to Javascript strings. It seems the lookbehind isn't working at all (as it seems you alread found out, uh, on 2nd reading...).
    So you have to think of something else. How about this one? Using parentheses in a find expression can be useful!
    var str = "Hello world!";
    var f = str.match (/"([^"]+)(?=")/);
    if (f)
    alert ("Result: "+f.join("\r"));
    else
    alert ("Nothing matches...");
    str = "Hello \"world\"!";
    f = str.match (/"([^"]+)(?=")/);
    if (f)
    alert ("Result: "+f.join("\r"));
    else
    alert ("Nothing matches...");

  • How to use String.replaceAll(String regex, String replacement)?

    hi,
    I'd like to use the String.replaceAll call to replace all occurrences of a pattern in a string with a string inputted from the user.
    The problem is that replaceAll seems process the replacement string first. For example, the code below won't work
    public class StringTest {
         public static void main(String [] arg) throws Exception {
              String input = "oooIoooIooo";
              input=input.replaceAll("I","\\");
              System.out.println(input);
    }So the only option seems to be to manually process the user input string into a form that can be accepted by String.replaceAll?
    The only thing I can find from looking through the API is that you'd need to convert each backslash to a double-backslash?
    is this the right thing to be doing?
    thanks,
    asjf

    just to clarify, at the moment I think the solution is to do this
    public class StringTest {
         public static void main(String [] arg) throws Exception {
              String input = "oooIoooIooo";
              String raw = "\\";
              input=input.replaceAll("I",raw.replaceAll("\\\\","\\\\\\\\"));
              System.out.println(input);
    }

  • EZVPN public internet split tunnel with dialer interface

    I have a job on where I need to be able to use EZVPN with split tunnel but still have access to an external server from the corporate network as the external server will only accept connections from the corporate public IP address.
    So I have not only included the corporate C class in the interesting traffic but also the IP address of the external server.  
    So all good so far, traffic for the corporate network goes down the tunnel as well as the IP address for the external server.
    Now comes the problem, I am trying to send the public IP traffic for the external server out of the corporate network into the public internet but it just drops and does not get back out the same interface into the internet.
    I checked out this procedure and it did not help as the route map counters do not increase with my attempt to reach the external router.
    http://www.cisco.com/c/en/us/support/docs/security/vpn-client/71461-router-vpnclient-pi-stick.html 
    And to just test the process, I removed the split tunnel and just have everything going down the tunnel so I can test with any web site.  I also have a home server on the network that is reached so I can definitly reach into the network at home which is  the test for the corporate network I am trying to reach.
    Its a cisco 870 router and here is the config
    Router#sh run
    Building configuration...
    Current configuration : 4617 bytes
    version 12.4
    no service pad
    service timestamps debug datetime msec
    service timestamps log datetime msec
    no service password-encryption
    hostname Router
    boot-start-marker
    boot-end-marker
    logging message-counter syslog
    enable secret 5 *************************
    enable password *************************
    aaa new-model
    aaa authentication login default local
    aaa authentication login ciscocp_vpn_xauth_ml_1 local
    aaa authorization exec default local 
    aaa authorization network ciscocp_vpn_group_ml_1 local 
    aaa session-id common
    dot11 syslog
    ip source-route
    ip dhcp excluded-address 192.168.1.1
    ip dhcp excluded-address 192.168.1.2
    ip dhcp excluded-address 192.168.1.3
    ip dhcp excluded-address 192.168.1.4
    ip dhcp excluded-address 192.168.1.5
    ip dhcp excluded-address 192.168.1.6
    ip dhcp excluded-address 192.168.1.7
    ip dhcp excluded-address 192.168.1.8
    ip dhcp excluded-address 192.168.1.9
    ip dhcp excluded-address 192.168.1.111
    ip dhcp pool myDhcp
       network 192.168.1.0 255.255.255.0
       dns-server 139.130.4.4 
       default-router 192.168.1.1 
    ip cef
    ip inspect name myfw http
    ip inspect name myfw https
    ip inspect name myfw pop3
    ip inspect name myfw esmtp
    ip inspect name myfw imap
    ip inspect name myfw ssh
    ip inspect name myfw dns
    ip inspect name myfw ftp
    ip inspect name myfw icmp
    ip inspect name myfw h323
    ip inspect name myfw udp
    ip inspect name myfw realaudio
    ip inspect name myfw tftp
    ip inspect name myfw vdolive
    ip inspect name myfw streamworks
    ip inspect name myfw rcmd
    ip inspect name myfw isakmp
    ip inspect name myfw tcp
    ip name-server 139.130.4.4
    username ************************* privilege 15 password 0 *************************
    crypto isakmp policy 1
     encr 3des
     authentication pre-share
     group 2
    crypto isakmp client configuration group HomeFull
     key *************************
     dns 8.8.8.8 8.8.8.4
     pool SDM_POOL_1
     include-local-lan
     netmask 255.255.255.0
    crypto isakmp profile ciscocp-ike-profile-1
       match identity group HomeFull
       client authentication list ciscocp_vpn_xauth_ml_1
       isakmp authorization list ciscocp_vpn_group_ml_1
       client configuration address respond
       virtual-template 3
    crypto ipsec transform-set ESP-3DES-SHA esp-3des esp-sha-hmac 
    crypto ipsec profile CiscoCP_Profile1
     set security-association idle-time 1740
     set transform-set ESP-3DES-SHA 
     set isakmp-profile ciscocp-ike-profile-1
    crypto ctcp port 10000 
    archive
     log config
      hidekeys
    interface Loopback10
     ip address 10.0.0.1 255.255.255.0
     ip nat inside
     ip virtual-reassembly
    interface ATM0
     no ip address
     no ip redirects
     no ip unreachables
     no ip proxy-arp
     ip flow ingress
     no atm ilmi-keepalive
    interface ATM0.1 point-to-point
     description TimsInternet
     ip flow ingress
     ip policy route-map VPN-Client
     pvc 8/35 
      encapsulation aal5mux ppp dialer
      dialer pool-member 3
    interface FastEthernet0
    interface FastEthernet1
    interface FastEthernet2
    interface FastEthernet3
    interface Virtual-Template3 type tunnel
     ip unnumbered Dialer3
     tunnel mode ipsec ipv4
     tunnel protection ipsec profile CiscoCP_Profile1
    interface Vlan1
     ip address 192.168.1.1 255.255.255.0
     no ip redirects
     no ip unreachables
     no ip proxy-arp
     ip inspect myfw in
     ip nat inside
     ip virtual-reassembly
     no ip route-cache cef
     no ip route-cache
     ip tcp adjust-mss 1372
     no ip mroute-cache
     hold-queue 100 out
    interface Dialer0
     no ip address
    interface Dialer3
     ip address negotiated
     ip access-group blockall in
     no ip redirects
     no ip unreachables
     no ip proxy-arp
     ip mtu 1492
     ip flow ingress
     ip nat outside
     ip virtual-reassembly
     encapsulation ppp
     ip tcp header-compression
     ip policy route-map VPN-Client
     no ip mroute-cache
     dialer pool 3
     dialer-group 1
     no cdp enable
     ppp chap hostname *************************@direct.telstra.net
     ppp chap password 0 *************************
    ip local pool SDM_POOL_1 10.0.0.10 10.0.0.100
    ip forward-protocol nd
    ip route 0.0.0.0 0.0.0.0 Dialer3
    ip http server
    ip http authentication local
    no ip http secure-server
    ip nat inside source list 101 interface Dialer3 overload
    ip access-list extended VPN-OUT
     permit ip 10.0.0.0 0.0.0.255 any
    ip access-list extended blockall
     remark CCP_ACL Category=17
     permit udp any any eq non500-isakmp
     permit udp any any eq isakmp
     permit esp any any
     permit ahp any any
     permit tcp any any eq 10000
     deny   ip any any
    access-list 101 permit ip 192.168.1.0 0.0.0.255 any
    access-list 101 permit ip 10.0.0.0 0.0.0.255 any
    dialer-list 1 protocol ip permit
    route-map VPN-Client permit 10
     match ip address VPN-OUT
     set ip next-hop 10.0.0.2
    control-plane
    line con 0
     no modem enable
    line aux 0
    line vty 0 4
     password cisco
    scheduler max-task-time 5000
    end
    Router#exit
    Connection closed by foreign host.

    Thanks for the response.
    Not sure how that would help as I can connect into the internal network just fine, but I want to hairpin back out the interface and surf the internet from the VPN client.  The policy route map makes the L10 the next hop and it has NAT.

  • Regex to split a String

    Hi,
    Here's a little regex problem Jos e-mailed me the other day, to which I didn't find a satisfactory answer (I found one, but it's rather verbose). Chances are that there is no short (or simple) solution, but when this is the case with a certain problem, I usually know why there is no simple solution because of some limitation with the regex flavor I am using. However, I can't think of one with this problem.
    Also note that this problem can be easily (and far more efficiently) solved by writing a custom method, but I happen to like regex and am curious to know if there's some solution to this I missed.
    So, without further a due, here is the questions:
    Split a String T into parts with a maximum size N without splitting T on a certain sub string S. In other words: try to split a String in as large as possible parts (equal or less than N) without splitting it on a certain sub string.
    You can use only one split(...) call!
    Lets say S = abc and N = 5 then here are a couple of examples:
    T            = xyabcdefgabc
    T.split(...) = [xyabc, defg, abc]
    T            = xyzabcbbzzzabcabcbcacbyyy
    T.split(...) = [xyz, abcbb, zzz, abc, abcbc, acbyy, y]
    T            = xyzzzzabcbabczabcabcabcacbyyy
    T.split(...) = [xyzzz, zabcb, abcz, abc, abc, abcac, byyy]

    uncle_alice wrote:
    Okay, I give up. I can see how to do this with find(), but not with split(). I hope you haven't been waiting for me all this time... :DTo be frank, yes I have. You, sabre and maybe Darryl (in a good mood ; )). Ah well, I am now convinced I didn't overlook some easy shortcut.
    This is what I've cooked up:
    class Main {
        public static void main(String[] args) {
            String[] tests = {"xyabcdefgabc", "xyzabcbbzzzabcabcbcacbyyy", "xyzzzzabcbabczabcabcabcacbyyy"};
            String sub = "abc";
            int max = 5;
            String regex = String.format("(?<=\\G.{%d,%d})(?=%s)|(?<=\\G.{%d})", max-sub.length()+1, max-1, sub, max);
            System.out.println("regex = "+regex+"\n");
            for(String test: tests) {
                System.out.println(test);
                System.out.println("  -> "+Arrays.toString(test.split(regex))+"\n");
    }B.t.w. uncle_alice, this *\G* (previous match) functionality, is this some Java thing or does it exist in other regex flavors as well?

  • How to split a string around "." expression

    My code is:
    public String removeExtn(String resource){
              String[] splittedName = resource.split(".");
    System.out.println("LENGHT IS: "+ splittedName.length);
              if(splittedName.length >= 3)
                   resource = splittedName[0]+ "." + splittedName[1];
              return resourceName;
         * @param args
         public static void main(String[] args) {
              Test obj = new Test();          
              System.out.println(obj.removeExtn("myfile.xml.sample"));
    But it doesn't split the string around "." and given the arraylength 0. But if I try to use any another character (e.g. "," or ";") it works perfectly fine.
    Please help me.
    Thanks in advance.
    Mansi

    Hi mansi,
    I had a same kind of problem a few days back.
    What I learned was the split() method has a string expression in it, which is usually noted as regex .
    'Regex' is just a short form for 'regular expression'
    You may directly use the string variable you would split around in some cases or may want to use a '\\' before some of the characters.
    I can't place whole information here .So, let me give you that sun site link I read it from.
    This link deals with the whole string class.
    You may want to ctrl+F and split to read on split method.
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.htmlThis link talks about the regular expressions
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sumI got his for you from that link :
    \p{Punct} Punctuation: For One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ This is for your knowledge.
    And if you want a quick fix just for your code...
    that'ld be using a
    split(\p{.}) in place where u used a split(.)I have not tried that ...but u may want to!
    Hope that helps.
    Message was edited by:
    Kishorei20
    Message was edited by:
    Kishorei20

  • StringTokenizer vs. split and empty strings -- some clarification please?

    Hi everybody,
    I posted a question that was sort of similar to this once, asking if it was best to convert any StringTokenizers to calls to split when parsing strings, but this one is a little different. I rarely use split, because if there are consecutive delimiters, it gives empty strings in the array it returns, which I don't want. On the other hand, I know StringTokenizer is slower, but it doesn't give empty strings with consecutive delimiters. I would use split much more often if there was a way to use it and not have to check every array element to make sure it isn't the empty string. I think I may have misunderstood the javadoc to some extent--could anyone explain to me why split causes empty strings and StringTokenizer doesn't?
    Thanks,
    Jezzica85

    Because they are different?
    Tokenizers are designed to return tokens, whereas split is simply splitting the String up into bits. They have different purposes
    and uses to be honest. I believe the results of previous discussions of this have indicated that Tokenizers are slightly (very
    slightly and not really meaningfully) faster and tokenizers do have the option of return delimiters as well which can be useful
    and is a functionality not present in just a straight split.
    However. split and regex in general are newer additions to the Java platform and they do have some advantages. The most
    obvious being that you cannot use a tokenizer to split up values where the delimiter is multiple characters and you can with
    split.
    So in general the advice given to you was good, because split gives you more flexibility down the road. If you don't want
    the empty strings then yes just read them and throw them away.
    Edited by: cotton.m on Mar 6, 2008 7:34 AM
    goddamned stupid forum formatting

  • 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.

  • Using Regex to search strings......

    Hey guys,
    I'm trying to scan an html file for specific strings. Basically, I just store the entire html file as a one big long string and then use a regex to scan the string for specific keywords that I am looking for. However, I am not all that familiar with regular expressions in java, and, although I have spent a considerable amount of time reading over the tutorials, I can't seem to get my regular expression to produce the results that I want.
    +More specifically, what I am trying to scan the html string for is a keyword preceded by a non-alphanumeric character([/W] and followed by a non-alphanumeric character. Also, since the keywords generally represent country names, state names, state abbreviations, city names, and the like.....I really want to make the scan case-insensitive to the case format of the keyword except in the case that the keyword is an abbreviation (i.e., CA, IN, NY,etc. since making this case-insensitive would pick up a lot of garbage, especially in cases like: IN)+_.* As of right now, this is what I am using for my regex(and the results are all over the place):
    *String regex = "[/W]+"+"(?i)"+keyword+"[/W]+";*
    This just seems wrong! I've played around with it and, lets just say, the results have generally gotten worse. Does anyone have any ideas on how I should correctly format the regex to achieve the goal explained above?? Any and all help would be greatly appreciated. Thanks.

    A technique I find very useful in writing complex regex's is to split the regex into its parts and work on just the one part at a time. This helps me to easily see that the components match exactly what I think I am matching. Once I have every individual part working it is very easy to join them to create the entire match.
    Something like...
    String keywordRegex = "";
    String nonAlphaCharRegex = "";
    //..etc. etc
    String fullRegex = keywordRegex + "whateverIwantToMatchBetween" + nonAlphaCharRegex + ...

Maybe you are looking for