problem with String.replaceAll

Everyone does not understand why "10,00".replaceAll (".") * ","0") == '00' and not '0'?"

Looks like. * must match the whole string and replace it with '0 '.

With the help of 1.6.0_17

840419 wrote:
Everyone does not understand why "10,00".replaceAll (".") * ","0") == '00' and not '0'?"

Looks like. * must match the whole string and replace it with '0 '.

He does.

    public static void main(String[] arg) {
        //System.out.println("10.00".replaceAll(".*", "0"));
        Pattern p = Pattern.compile(".*");
        Matcher m = p.matcher("10.00");
        while(m.find()) {
            // the first find() greedily matches everything
            // the second find() matches a 0(zero)-length charsequence at the end
            System.out.printf("[%s]\n",m.group());
        }
    }

You want to

    public static void main(String[] arg) {
        //System.out.println("10.00".replaceAll(".+", "0"));
        Pattern p = Pattern.compile(".+");
        Matcher m = p.matcher("10.00");
        while(m.find()) {
            System.out.printf("[%s]\n",m.group());
        }
    }

Tags: Java

Similar Questions

  • Problem with string to Int conversion

    Dear friends,

    Problem with string to Int conversion

    I'll have a column where most of the values is digital. Only 4 values are not numeric.

    I have replaced the non-numeric values to numeric in order to maintain the data type.

    Grade.Grade DEAL WHEN "E4" THEN "24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' Grade.Grade OTHER END"

    This is the result as inactive

    Grade

    _0_

    _1_

    _10_

    _11_

    _12_

    _13_

    _14_

    15

    _16_

    _17_

    _18_

    _19_

    _2_

    _20_

    _21_

    _22_

    _23_

    _24_

    _3_

    _4_

    _5_

    _6_

    _7_

    _8_

    _9_

    Discount
    -            -            -

    Now I want to convert this value in digital and do some math

    So I changed the formula as below

    Cast (CASE Grade.Grade WHEN "E4" THEN "24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' Grade.Grade END as an INT. ELSE")


    Now I get the following error
    View display error
    Driver Odbc _ returned an error (SQLExecDirectW). _
    Error details
    Error codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    _State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 17001] Oracle error code: 1722, message: ORA-01722: invalid number in the OIC calling OCIStmtFetch. [nQSError: 17012] In bulk fetch failed. _ (HY000)
    SQL issued: SELECT cast (CASE Grade.Grade WHEN "E4" THEN "24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' Grade.Grade END as an int. ELSE") seen'Human Capital' 0 - Costing Manpower WHERE LENGTH (Grade.Grade CASE WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN "E4" THEN "23 ' ELSE Grade.Grade END) > 0 ORDER BY saw_0_

    Discount





    Could someone help me

    Concerning

    Mustafa

    Published by: Musnet on June 29, 2010 05:42

    Published by: Musnet on June 29, 2010 06:48

    Are you sure you don't have another non-digital value in your column. I want to get this filter temporarily just to check if your plaster works or not. If it works, then you can remove this filter.

  • Problem with string writing series

    I'm using labview to send commands to a device using the serial port com1.  Using the example VI "Base series in reading and writing", I can communicate with my hardware very well, can write and can read.   the problem comes when I want to edit the VI by using my own string instead of the string provided in the example.  When I create a string constant with the exact text that was in the example string box, I can not write my material.

    I don't understand why this wont work.  Is there something special about the example of the VI text 'string to write' box that I don't know?

    Help, please

    Thank you

    I know what you mean and it does not work like that.  For some reason if I use a string with \r\n constant it still does not work.

    Anyway, I solved the problem in a roundabout way.  The command I sent you is a word but both parties; first part, second part number.  I want to create a loop when the number changes.  I was able to do this by combining three channels, the first is a copy of the example string, the middle is my number converted to string, the third is a different copy of the string of examples.  Now it works and I can with my life

  • Problem with string comparison

    I have a web service that I use two compares two strings, one from the service web xml of my application.

    XML retrieves a string when I compare it like this

    If (xmlVersion == 'true') {}

    }

    It never enter the if condition when I print the value I get from the service I think like this (real).

    So, what's the problem here?

    The way you wrote the comparison. you simply compare the addresses of the two strings.

    Try this instead:

    xmlVersion.equals ("true").

    In fact, you might want to consider getting these out to the back to avoid would be Null Pointer Exceptions, like this:

    If (true".equals (xmlVersion)) {" "}

    }

  • Reading problem with string after - stabilizer

    I just imported 4 sequences of gopro black k in my calendar and practical cuts. I was sure to drag the images from the library to the timeline and match the settings of the sequence. The problem occurs after the addition of stabilizer of Warp. I made green bars, but reading the image is grainy and stutters. I read resolution full game and exports come out the same way in a variety of formats. VERY frustrated with this recurring problem. Help, please. Thank you.

    Just spoke with a technician. Only necessary to upgrade to version 2015.0.2

  • Problem with string to Long in Blackberry JDE and Eclipse w / Blackberry plugin

    I'm trying to convery a string to a long use in a persistent store.  I'm following the doc of Blackberry on the process.  When I type the chain and right click on "Convert String to Long" is gray in Eclipse and the BB JDE.

     applepie
    
      String key = new string ("applepie");
    
      String key = "applepie";
    

    those are the means I m try in both environments.

    What I am doing wrong?

    There must be something simple.

    I'm probably not see the forest because of the trees.

    You must select this channel.

    first select the channel using the mouse (as when we do to cut or copy)

    After that right-click on this channel.

  • Problem of string manipulation

    Hello

    I have a problem with string manipulation. I need to compare the character with his next character.
    as an example consider the string as "fat".
    'b' must be compared with 'o'.
    "o" by 'l' and so on.
    I used below the code snippet.


    for (int i = 0; i < s.length (); i ++)
    {
    int j = i + 1;
    If (s.charAt (i) == s.charAt (j))
    {
    status = false;
    }

    on the other
    {
    status = true;
    }
    }

    But I get an error message. Help, please. Thanks in advance.

    Published by: Vinayjgeorge on June 1, 2011 12:26 AM

    Published by: Vinayjgeorge on June 1, 2011 12:39 AM

    (1) for the validation of code, use the code tags so that it will be readable: http://forums.oracle.com/forums/ann.jspa?annID=1429

    (2) "I get an error" means nothing. Do you think that there is only a single possible error that may appear in the Java code and the only possible thing that can? If this isn't the case - in other words, if you don't know that there are different errors and causes - so why you thought that simply say "I get an error" without any details would be sufficient to describe the error? You must copy and paste the exact, complete error message, if you want to communicate clearly what problem you encounter so that people can help you.

    Please put a little more thought in upcoming posts.

    That said, in this case, it is easy to see an error you will get. Loop tells you ' for each character in the string, compare this character with the next. " You can see why it does not work? When you get to the last character, the comparing it to that is not possible, because there is not a next. You say "for all characters except for the last, compare it to the following."

    Once correct you that, you always seem to have a logic error. You are just blindly setting status to each character, so when you're done, just status will contain everything that produced the last comparison. It might go back between true and false to each character, but the only one that will count will be the last.

    Edited by: jverd May 31, 2011 12:06

  • FDK: Problem with line breaks / carriage returns

    Hello


    I met a strange problem with strings when you use the FrameMaker API. We have a FAPI customer who translated documents FM reading in their content, by replacing their text by the new translated text and in return the change in writing.

    However, I found that some strings are starting with a \r (carriage return) character, when we read in and when we write their return, they begin with \r\n, which moves text to the bottom line, and can break things as references etc. I don't know exactly why this is happening, we are using Visual C++ and we do a lot of conversions between classes CString and StringT types so maybe this conversion process are to do.

    To be honest, I find the appearance of newlines and carriage returns in the frame channels somewhat odd frame API breaks up the text of a paragraph into fragments for you anyway, so I would have thought that the use of these characters is redundant. That's a big assumption however so correct me if I'm wrong.

    We have implemented a work around by which our program strips newlines off channels before writing their return

    but in reality, what we really need to undress returns to the main line of strings, before starts the printable text in a string.

    I wonder what others have to say about this WRT its security approach. Any advice would be appreciated, thanks

    Eric

    Eric,

    I did a little greater experimentation, based on my previous comments (sorry, should have done that before I clicked on the Post before.)  When I programmatically add a \r one paragraph, I don't see no effect in page layout. This is consistent with my suspicions so far. I really think that, maybe, these characters are misleading and should be removed from the beginning.

    Russ

  • LabVIEW 8.5 problems using strings with MATLAB Script node

    I am having some problems that seem to be a bug that I can not understand how to solve using strings in the MATLAB script node.

    I have two subVIs that make some calculations and both include a variable called "errortext" is a string. The two subVIs do their calculations using the MATLAB script node, so all the outputs are defined in the script node.

    The first sub - VI outputs that string and a number. The string is sent to an indicator on the front panel. The number is sent to the second Subvi which performs some calculations more and then returns another string of the same name to an indicator on the front panel. This second string is different from the first (error different two messages should appear).

    I did have problems with this in the past until this morning. This morning, it seems that two of these channels are now somehow mystically connected to each other. The second string repeat that what the first channel said despite the fact that the first string is not be linked to the Subvi where lives the second string. The only link between the two is a calculated value of double which went from #1 to the Subvi #2 Subvi.

    I tried many things: I tried to rename the strings so that they do not have the same name. Initially, he would not let me and gave me an error saying that the renowned string was a undefined variable (which is ridiculous). After removing and replacing things, I finally managed to do so I would change the name, but now it displays nothing at all and even more I think it might still display a completely different another string in my code!

    I also tried to remove the channel indicator and replace it. Yet once, it wouldn't let me initially. I would like to highlight, press DELETE and nothing. Finally after replacing all the subVIs with them, I was able to remove the flags, but this did not help the problem.

    Any idea for these problems pecular is greatly appreciated!

    I totally understand what you did, you were talking about variables in your fist post, and it was not clear if you were referring to a variable you have defined in the Matlab code, or you try to call a variable indicator/control, where is often seen on this forum (and who isn't). That said, the crux of The Matlab Script communicates with Matlab via ActiveX, and when you use a command window opens small. This is the workspace of Matlab environment. A variable that you define in a Matlab Script node will be visible in the other, even if it's in another VI (see attached for an example, figure). This is because the script nodes are running in the same environment space. It seems to me that if this is what is happening.

  • Problem with the Polycom endpoint dial string via VCS

    Greetings,

    Currently I have an environment using a set of standalone Polycom endpoints (mixture of VSX/HDX units).  We have recently installed VCS - c / VCS-e / TMS and despite a few problems with the SIP registration on some of the older endpoints and management through TMS, all support works well.  The only remaining problem is when there are a number of business partners using the extensions in their chains of H.323 dialing that works very well for the Polycoms during the use not VCS - c as a guard in the numbering of the format #.  When you use this same dial string and endpoints are registered in VCS - c then the only thing it is indicated in the call history is a number of , which fails.

    I am aware that different manufacturers have historically managed extension dialing differently since ISDN only and has apparently been perpetuated until today.  However, it's a pretty critical need still at this stage and I am looking for input on chipboard VCS supports the use of extension component in the dial string (or did once the call is connected to a gateway is the host).  If so, is there a specific format for this connection string which can support both the end points of Polycom and VCS able to interpret correctly?  Does anyone have this working?

    Latest versions of software are on all components.

    Thank you in advance for any thoughts you may have!

    Hi Readamson,

    using the syntax of "device-IP-address ##extension" to compose a H323 device isn't a way standard of doing things, it is approach of Polycom extension numbering that VCS does not understand without changing the alias of a '[email protected] / * /' format.

    Assuming that the address-IP-receives the message SETUP H225 VCS-E, he does the SETUP message? Is there a way that you can configure this device to end to remove the [email protected]/ * /' part of the route the call to the post and the dialed number?

    Visit this link:

    https://supportforums.Cisco.com/thread/2129307

    Best regards, Ahmad

  • Problems with arguments, vector + AIR NativeProcess 'not supported'. &lt; String &gt;

    I want to create an AIR application that will execute a call from style of command line (extendedDesktop) on an .exe file with an argument that is passed to it.

    I followed the example of setting as shown on this page to reference Adobe. However, when I try to create a vector. < String > I get error "error #1007: instantiation attempted on a non-constructeur.»

    This occurs on the following line:

    var processArgs:Vector. < String > = new Vector ["< String >"] ();

    I also tried without the declaration of arguments and calling just the .exe without arguments, and I get the error "" the NativeProcess could not be started. "" Not supported in the current profile. "" I have several put supportedProfiles in place in my folder (including desktop computers and extendedDesktop) but don't know how to test and debug the file in Flash Builder with rights of extendedDesktop. "

    Hello

    In my opinion, Adobe docs aren't clear on the requirements of "NativeProcess" during the creation. All the articles/docs, you find via references to research that we need to ensure that this descriptor is modified, which includes:

    extendedDesktop

    for example; http://www.Adobe.com/devnet/air/Flex/articles/air_screenrecording.html

    While it seems to be necessary only for generation of deployment to ensure that the application is built in 'extended' profile that Active native installer and access to the native process.

    In any case running Flash Builder with integration of built-in adl should allows you to test in my opinion (as I never had to manually change the descriptor creation/trials).

    I suggest you to make sure that all things are built as planned and start the new thread on the creation of problems with Flash Builder and adl (as it seems that he is not running in the correct privileges - so you are not able to test/author some features). I assume that you use the administrator account on your machine (and Flash Builder has been installed and then run under the same account).

    (note: I'm on Mac)

    Kind regards
    Peter

  • String.replaceAll () takes an argument of regex?

    For the experienced:


    It is not not to solve a problem to find work on hand made, but something for the discussion of other possibilities.

    I have a file which must cut them before use. The file has several lines, and for each line of the format is ('X' is used to mark the beginning and the end of the line to show the invisible white space):
    X12345678   9876543210 X
    I need to replace the three spaces between two numeric characters with one and eliminate space of tailings. My code:
    String line = null;
    while ((line = inputStream.readLine()) != null) {
        Pattern pattern = Pattern.compile("\\s+");
        Matcher matcher = pattern.matcher(line);
        line = matcher.replaceAll(" ").trim();
        System.out.println("(" + line + ")");
    Which works very well and produces the desired result:
    (12345678 9876543210)
    Would but not be simpler if replacement of the String class methods would do the same job? It is, say,
    String line = null;
    while ((line = inputStream.readLine()) != null) {
        line.replaceAll("\\d+", " ").trim();
        System.out.println("(" + line + ")");
    I do this using JDeveloper 11.1.1.3, located in C:\Oracle\Middleware\jdeveloper\jdeveloper.exe and found out, C:\Oracle\Middleware\jdk160_18\jre\bin\client\jvm.dll is probably the JDK using the JDeveloper. I checked the API document online for Java version 6 to http://download.oracle.com/javase/6/docs/api/index.html, and it shows that the String class has these replacement methods that take the regex:
    String replaceAll(String regex, String replacement) 
    String replaceFirst(String regex, String replacement) 
    But when coding, typing < font color = "green" > replace < / police > as a result of the variable string < font color = "green" > line < / police >, all the insight of Code appears include:
    replace(Char, Char)                  String
    replace(CharSequqnce, CharSequence)  String
    replaceAll(String, String)           String
    replaceFirst(String, String)         String
    This seems to say that regex is not supported. If I do not take into account the suggestion of the foresight of Code and try anyway:
    line.repaceAll("\\d+", " ");
    
    or
    
    line.replaceAll("  *", " ");
       // This second attempt uses the familiar regular expression in unix,
       // such as would be used in
       // $ echo $line | sed 's/  */ /g'
    JDeveloper complain about this attempt. But it does not work either, simply echo back which entered into him.

    What I want to do is play with it to find a way of writing acceptable regular expressions in the JDK in JDeveloper. What the API documentation has said is that regex is accepted and taken in charge, but his behavior, we know not if this is the case with the JDeveloper, or if it is supported, but the suggestion of the insight of Code isn't fair and my regular expressions are not correct.

    All suggestions and insight would be much appreciated.


    Newman

    System.out.println ("1 2 3 4".replaceAll ("\\s {2},", "X")); is back "X 1 2 X 3 X 4"(p. ex. espaces consécutifs seulement sont obtenant remplacés). "»
    I have not tested, but the \s character class may not include new lines. You can use \n If you want to include line breaks as well. Also, I used JDeveloper and jdk, I used is one that comes with Jdeveloper(e.g. \Oracle\Middleware\jdk160_21).

    Edited by: Hyangelo may 9, 2011 11:03

    Edited by: Hyangelo may 9, 2011 11:05

  • Some problems with Toshiba TV 47L 6453

    Hello

    I have some problems with this TV, as follows

    -I need to re tune the tv several times a day to receive a complete list of channels.
    -The guide shows a TNT channel with program information, when a program is selected, I get a message indicating that the channel can not be tuned. However when I touch the channel it displays the string correctly.
    -Program data is not displayed on several channels. Sometimes this can be improved in re-tuning.

    Can I have a TV that is defective, or is it considered normal for this toshiba tv. I have a lot running off the same ariel who doesn't have these problems of adjustment so I know that it's not that older television.

    Any help here then. Just to add insult the YouTube app decided to stop working. This TV keeps guessing you as to what will work on any given day.
    Without a doubt the worst little waste tech, I had the misfortune to buy for many years. It has a large image. Such a shame, he struggles to view freeview channels, or smart TV applications.
    I will never buy an another Toshiba product again. The previous 7 years tv, that I had to be upgraded is far superior to this piece of unreliable junk. Hope this helps someone to make a wise buying decision. Do not buy this TV and become another victim of toshiba.

  • Problem with the sensor of pressure and NI 9205 with NI 9263

    I have a bridge pressure sensor based with a range of 0 - 5000 psi and requires a 10 V excitation. The output is 3 mV/V. I plugged on a cDAQ with a NI 9263 providing excitement V 10 and a NI 9205 to read the output values. I would expect a 0-30 mV output corresponding to 0 - 5000 psi, correct? (Incidentally, the NI 9205 module must be accurate to 0,1 mV or this should lead to a precision of about 16 psi, right?).

    However, when I tested it in fact the sensor on the run a test ranging from 0 to 1000 and back to 0 lb/po2 (now for quite awhile to States of pressure) the values I get from the NI 9205 are about 204.614 mV for 0 lb/po2 and then goes 204.867 mV to 1000 lb/po2 (actual results are noisy (, so these are averages). I enclose the SignalExpress file used for the test as well as the Excel file containing the resutls. Testing was performed with a number of other active sensors (load and displacement, LVDT and gagues strain gauges) in addition to the pressure that I'll eventually use them for my experience. In the SignalExpress file, the pressure transducer is the only sensor receives the excitement of the NI 9263 (ao_0) and ai_3 on the NI 9205 module.

    So this time I tried to run the test again, but changed the SignalExpress file (second .seproj attached) to include only the pressure transducer. But now I don't have an answer at all by the transducer (it remained simply flat).

    As to the connection of the transducer material, it is a connection 4-wire (excitement, - Exciation + Signal - Signal). I plugged the cables from signal to pins 4 and 23 (AI3 and AI11) for a differential pair. Then, I plugged the son of excitement to the pins 0 and 1 (AO0 and COM). Finally, I took a wire jumper and connected 23 on the NI 9205 module PIN to pin 1 on the NI 9263. I made this last step at the suggestion of support OR for a previous problem with a string potentiometer. This stage connected the ground between the two modules (the sensor did not answer with a pressure change when I don't have the wire).

    I appreciate any help as to why. I did not receive a 0-30 exit mV.

    his does not work like that.

    The probe should @30mA to 10VDC.  There is only available from the canal AO 9263 1mA.  you need another power supply.

  • Problem with typecasting function

    Hello world

    I have a problem with the conversion in labview function. I want to save my data in a binary format, so I use the conversion feature to convert data types to string format. Subsequently, these files must be read into Matlab and other software. Everything works directly in labview but is not with other software. For example, if I want to save a value of 1 (U16) I can only read a value of 256 in Matlab. I guess it has something to do with the effects of Mismatching described in help. But how can I fix? Can someone help me, that would be great?

    Thank you very much!

    Johannes

    I want to save the value 1 (U16), I can read only instead of a value of 256 in Matlab

    You have a problem (as said Mercurio, "Boutien") byte order.

    A U16 takes 16 bits, or two bytes.

    When sending two bytes in the meantime, both parties must agree on which one comes first.

    For many years, the standard was "big-endian", that is, the byte the most signiificant came first.

    Intel came and went against the standard byte, i.e. 'little-endian' or less important first.

    LabVIEW has 'Big-Endian' as the standard for the transfer (he was born on non-Intel architectures).

    If both sides of the Exchange do not agree on the method, you will get the symptoms you describe,

    If the two bytes are 00 01, one side which will see as 00 01 = an and the other side will see it as 01 00 = 256.

Maybe you are looking for

  • The right edge is off the screen and I can't adjust the width.

    Somehow, I have the column on the right side of the screen and now it can not reach to reduce the column width, so I can see the part of the message.

  • How to unsubscribe or cancel the apple music?

    How to unsubscribe or cancel the apple music?

  • Computer not finding printer on the network

    I have an OfficeJet Pro 8600 Plus with a wireless connection to my home network, E2000 Cisco router. I have install the printer using the software that comes with it. Everything worked fine for several months, but recently, I found that my network co

  • Get airport utility to forget the other devices on the network view

    Hello Is it possible to get the Airport utility to forget other devices, it's on the graphic display? I live on a college campus so it displays about 15 other aircraft from the airport in the vicinity of my home and I would like to see it just mine!

  • Full ink tank cleaning

    My Photosmart C410a printer a lot of ink tanks that are used to catch ink when the cartridges are cleaned or the preinter passes through a print prep cycle.  I need help on how to access these tanks to clean them.  These tanks are located under the p