Changing a char in array.

Hello!
I'm writing a program using Properties to read values from a file. But some of the keys have spaces in them, and then it will return null.
So instead I converted the string it converts it to a char array, in which i want it to change all the blank spaces to underscores, and then reassemble the array as a string. Do anyone know how to do this, or know a simpler way than mine?
Thanks in advance, TheJuice.

Do you inspect the original string object, or the one returned from the replaceAll method?
Remember that String is immutable.
Consider this:
public class TestReplace {
     public static void main(String[] args) {     
          String originalStringObject = "Text with\tWhiteSpaces";
          String replacedString = originalStringObject.replaceAll("\\s", "_");
          System.out.println(originalStringObject);
          System.out.println(replacedString);
}- Roy

Similar Messages

  • Changing content in an array

    can someone help me with changing content in an array. The index will be specified by the user entering the index number.
    eg
    Enter the item number to Change
    1
    Then I need to replace the data in this index with new data.
    I am very new to java so I am sorry if this seems like a stupid questions. Your help is much appreciated.
    thanks

    public void modifyIt(String[] myArray){
      System.out.println("Which index?");
        int index = readResponse() //read in response somehow
      System.out.println("Whats the new data?");
      String data = readResponse() // read in response
      myArray[index] = data;
    }

  • Event Structure's value change, not detecting changes when tabbing thru array of clusters

    Hi!  I have an array of clusters (int, int, string, int) control, and want to detecting changes made to the it.  I used the Event Structure's value change case on the array, it works excellent except that it'll only detect the changes when you click out of the element or press the enter key (the one by the numbers, not carriage return).  I want it to detect the changes when I tab thru the cluster or array too, but I can't figure it out... Does anyone have any ideas?
    Thanks!

    mfitzsimons wrote:
    altenbach
    Tried Value Change with my example done in 7.1 and it doesn't trgger an event.  That is why I suggested Mouse Down.
    Curious. I did a few minor edits in 8.0 before saving as 7.1, but the simple value change event got triggered just fine when the value vas terminated with a tab in 7.1. Every time.  Strange....
    Are you on 7.1 or 7.1.1? Maybe there's a difference (I am using 7.1.1).
    LabVIEW Champion . Do more with less code and in less time .

  • [svn:bz-trunk] 20754: My latest EndpointPushNotifier change changed the style of the code quite a bit  (sorry for that, it was my IDE settings getting in the loop here) I only changed one char line 389.

    Revision: 20754
    Revision: 20754
    Author:   [email protected]
    Date:     2011-03-10 03:36:05 -0800 (Thu, 10 Mar 2011)
    Log Message:
    My latest EndpointPushNotifier change changed the style of the code quite a bit (sorry for that, it was my IDE settings getting in the loop here) I only changed one char line 389.
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/client/EndpointPushNotifier.java

    I seem to have fixed it by putting <div  class="clearfloat"></div> after the navigation bar?

  • Fact columns Datatype is changing from char to int in OBIEE 11g

    Hi ,
    I am taking measure columns - "product description","tot cost" against a dimension "project name" .
    I am generating this report in a planing form and OBIEE .
    in planing form :
    product description tot cost
    project name
    P1 A 1500
    p2 B 1700
    p3 C 1800
    in obiee report :
    product description
    project name
    P1 16 1500
    p2 17 1700
    p3 19 1800
    Somehow , measure's datatype are getting changed from char to number , in OBIEE report.
    By default , the data type for all fact's is Double .I tried changing that to varchar , but result is same .
    Do I need to change anything in physical layer / RPD .
    OBIEE version : 11.1.1.6
    Essbase version : 11.1.2

    Hi ,
    Thanks for your reply . To confirm , the data type of product description column is "double" in essbase .
    I found out ,thers's a RDBMS table , consisting of two columns - ID, text value . where product description's are in text value's with the corresponding ID's(integer values) .
    Now , when I am creating a form in planning , its fetching the text values of product description (there's some inbulit setting's available for this in plannng) .
    However , in obiee its fetching the ID values of product description .
    So ,
    1. Is there any similer setting I can do for OBIEE , so that it's fetches only text value's of product description .
    2. If not , then I have to join the essbase fact table with this RDBMS table . I am not sure how to do it .

  • Re: Is it possible to change row colors on array fields ors

    HI Martin!
    Yes, it is possible to change row colors on array fields.
    I have attached a PEX (tools.pex) which has an object which changes FillColor
    and PenColor for Arrays. The PEX has it's own test window, so you can try
    various combinations. (There are a few other Objects in the Project which are
    not relevant
    I'm not sure that you can change colors on individual choices in a scroll list.
    I haven't tried playing around with it.
    The test window actually changes the color of scroll lists as well.
    The object keeps track of which rows have changed color, same with pen color, so
    that when you scroll it keeps track of which rows are a different colors.
    The pex is self-contained, just import the file and do a test run.
    Please let me know if you have any problems.
    -later
    -labeaux
    Is it possible to change row colors on array fields or scroll lists?
    I need to create a list field that will allow me to dynamically change the
    fillColor and/or penColor attributes of individual rows. (I just want to
    highlight the rows, and those seem to be the obvious attributes...) It appears
    you can't do that on scroll lists (the elements are list elements, and don't
    have those attributes) and I can't figure out how to do it on an array field
    either. Any ideas for how to accomplish this?
    -Martin ([email protected])

    FreshWebmuse,
    Version 2 of iCal has the "Group Calendar" feature. It was released as part of Mac OS X v10.4, and if you really want/need that feature you will have to upgrade to Tiger.
    ;~)

  • How do i change 2 row of array into waveform with delta time and time

    Hello,
    How do i change 2 row of array into waveform with delta time and time
    so the waveform graph will display two waveform,
    waveform, not cluster =]
    and how to extract 1d array from waveform?

    Hi AxE,
    Here is an example VI, that do what You asked for.
    Both requests.
    Hope it Helps...
    Attachments:
    2D_to_Waveform.vi ‏75 KB

  • Sort(); changes key numbers of array

    Hello!
    I have a question about using function sort();
    I set the initial key of array to be 1 (instead of default 0). Everything goes OK until I sort the array. After sorting the array initial key value sets itself back to zero.
    Here is the example:
    <?php
    $var = array(1 => "Good", "Better", "The Best");
    foreach ($var as $index => $value)
         echo $index." - ".$value."<br />";
    sort($var);
    foreach ($var as $index => $value)
         echo "<br />".$index." - ".$value;
    ?>
    How to avoid the change of the initial array key?
    The output should be:
    1 - Better
    2 - Good
    3 - The Best

    DissidentPJ wrote:
    I have a question about using function sort();
    I set the initial key of array to be 1 (instead of default 0). Everything goes OK until I sort the array. After sorting the array initial key value sets itself back to zero.
    Yes, of course, it will. If you read the PHP manual page for sort(), it says quite clearly "This function assigns new keys to the elements in array. It will remove any existing keys that may have been assigned, rather than just reordering the keys."
    PHP has a large number of sort functions to handle a variety of requirements. However, what you want to do is to reorder the values AND renumber the keys. The simple way to do it is to use sort(), which puts the values in the right order starting at 0. Just add 1 to the key when you use it.

  • [svn:osmf:] 11069: Minor API change: Use Vector not Array for MediaElement. get traitTypes.

    Revision: 11069
    Author:   [email protected]
    Date:     2009-10-21 16:52:10 -0700 (Wed, 21 Oct 2009)
    Log Message:
    Minor API change: Use Vector not Array for MediaElement.get traitTypes.  Approved by dev team. Should be no impact to sample apps, unit tests, or test apps.
    Modified Paths:
        osmf/trunk/framework/MediaFramework/org/osmf/media/MediaElement.as
        osmf/trunk/framework/MediaFramework/org/osmf/proxies/ProxyElement.as

    Revision: 11069
    Author:   [email protected]
    Date:     2009-10-21 16:52:10 -0700 (Wed, 21 Oct 2009)
    Log Message:
    Minor API change: Use Vector not Array for MediaElement.get traitTypes.  Approved by dev team. Should be no impact to sample apps, unit tests, or test apps.
    Modified Paths:
        osmf/trunk/framework/MediaFramework/org/osmf/media/MediaElement.as
        osmf/trunk/framework/MediaFramework/org/osmf/proxies/ProxyElement.as

  • How to change alpha of an array?

    It's me again.
    I am trying to dynamically change the alpha value of a set of movieclips on a timer.  The timer works but I get an error message from the function.     
    This is the error:
    TypeError: Error #1010: A term is undefined and has no properties.
    at piedacoulisse_timer_fla:MainTimeline/zoom/piedacoulisse_timer_fla:onTime()[piedacoulisse_ timer_fla.MainTimeline::frame1:124]
    at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
    at flash.utils::Timer/flash.utils:Timer::tick()
    This is the code:
      var txt:Array = ["txt1","txt2","txt3","txt4","txt5"];
      var flashTimer:Timer = new Timer(3000,5);
      flashTimer.addEventListener(TimerEvent.TIMER, onTime);
      flashTimer.start();
      var frame:int = 0;
      function onTime(evt:TimerEvent):void{
       zoomIn.slider_mc.txt[frame].alpha = 1;  \\ line 124
       frame ++;  
    Can anyone tell me what the problem is and how to fix it?

    Sorry guys, no luck.  I tried all three suggestions and got the same error.  I ended up using timeline animation to change the alpha of my movieclips.  That worked but I am getting the error again when I try to stop some of the mc's from playing.  Here's the error:
    TypeError: Error #1010: A term is undefined and has no properties.
    at piedacoulisse_timer3_fla:MainTimeline/zoom/piedacoulisse_timer3_fla:onTime()[piedacouliss e_timer3_fla.MainTimeline::frame1:136]
    at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
    at flash.utils::Timer/flash.utils:Timer::tick()
    Here's the complete code, in case there is something I am not seeing elsewhere in the program:
    slider_mc.tickMark_mc.stop();
    slider_mc.stop();
    var myRectangle:Rectangle = new Rectangle(9,9,125, 420);
    var slideRectangle:Rectangle = new Rectangle(body_mc.x + 24.5,body_mc.y + 1,219.5,.01);
    var startSlide:Number;
    var deltaSlide:Number = 0;
    var startMoveX:Number = 0;
    var startMoveY:Number = 0;
    var endMoveX:Number = 0;
    var endMoveY:Number = 0;
    var contactTop:Boolean = false;
    var contactBottom:Boolean = false;
    var contactPoint:String;
    body_mc.addEventListener(MouseEvent.MOUSE_DOWN,pickUp);
    body_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
    body_mc.addEventListener(MouseEvent.MOUSE_OUT,dropIt);
    slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,beginSlide);
    slider_mc.addEventListener(MouseEvent.MOUSE_UP,stopSlide);
    slider_mc.addEventListener(MouseEvent.MOUSE_OUT,stopSlide);
    topMask.addEventListener(Event.ENTER_FRAME,moveMask);
    botMask.addEventListener(Event.ENTER_FRAME,moveMask);
    bodyMask.addEventListener(Event.ENTER_FRAME,moveMask);
    stage.addEventListener(Event.ENTER_FRAME,zoom);
    //  blockIt stops the draggable mc's when they hit the phone_mc
    function blockIt(event:Event):void{
    if(topMask.hitTestObject(phone_mc) == true){
      reply.text = "top hit";
      contactTop = true;
      event.currentTarget.stopDrag();
      contactPoint =  "top";
      nudgeIt(null);
    }else if(botMask.hitTestObject(phone_mc) == true){
      reply.text = "bottom hit";
      contactBottom = true;
      event.currentTarget.stopDrag();
      contactPoint = "bottom";
      nudgeIt(null);
    }else if(bodyMask.hitTestObject(phone_mc) == true){
      reply.text =  "body hit";
      event.currentTarget.stopDrag();
      contactPoint = "body";
      nudgeIt(null);
    //  drags the hit-detection objects - I needed to do this to allow for a U-shaped object to surround another object.
    function moveMask(event:Event){
    topMask.x = body_mc.x+19;
    topMask.y = body_mc.y+108;
    botMask.x = slider_mc.x+32;
    botMask.y = slider_mc.y+108;
    bodyMask.x = body_mc.x+100;
    bodyMask.y = body_mc.y+38;
    //  drags the movable mc's
    function pickUp(event:MouseEvent):void{
    event.currentTarget.startDrag(false,myRectangle);
    slider_mc.addEventListener(Event.ENTER_FRAME,followMe);
    body_mc.addEventListener(Event.ENTER_FRAME,blockIt);
    startMoveX = event.currentTarget.x;
    startMoveY = event.currentTarget.y;
    contactTop = false;
    //  drops the movable mc's
    function dropIt(event:MouseEvent):void{
    event.currentTarget.stopDrag();
    slider_mc.removeEventListener(Event.ENTER_FRAME,followMe);
    endMoveX = event.currentTarget.y;
    endMoveY = event.currentTarget.y;
    contactBottom = false;
    //  moves the slider with the body when it is dragged
    function followMe(event:Event) {  
         slideRectangle.y = body_mc.y;
      slideRectangle.x = body_mc.x + 24.5;
      slider_mc.x = slideRectangle.x + deltaSlide;
      slider_mc.y = body_mc.y;
    //  drags the slider along the body
    function beginSlide(event:MouseEvent):void{
    event.currentTarget.startDrag(false,slideRectangle);
    deltaSlide = slider_mc.x - slideRectangle.x
    contactBottom = false;
    // drops the slider
    function stopSlide(event:MouseEvent):void{
    event.currentTarget.stopDrag();
    // adjusts the postion of the draggable mc's to just butt up against the phone_mc - I did this so the mc's can be dragged again.  Without it, they are
    locked in place by the hitTest.
    function nudgeIt(event:Event):void{
    if(contactPoint == "top"){
      body_mc.x = body_mc.x - 1;
    }else if(contactPoint == "bottom"){
      slider_mc.x = slider_mc.x + 1;
    }else if(contactPoint == "body"){
      body_mc.y = body_mc.y - 1;
    // "zooms" in on the image and adds text commentary.  tickMark and oval mc's animate and then stop
    //  This is where the error messages started appearing
    //  Lines 136 137 and 138 all throw the same error
    function zoom(event:Event):void{
    if(contactTop == true &&contactBottom == true){
      body_mc.removeEventListener(MouseEvent.MOUSE_DOWN,pickUp);
      slider_mc.removeEventListener(MouseEvent.MOUSE_DOWN,beginSlide);
      var zoomIn:MovieClip = new MovieClip;
      zoomIn.addChild(phone_mc);
      zoomIn.addChild(body_mc);
      zoomIn.addChild(slider_mc);
      zoomIn.scaleX = 2.5; zoomIn.scaleY =2.5;
      addChild(zoomIn);
      zoomIn.x = -150; zoomIn.y = -350;
      slider_mc.tickMark_mc.gotoAndPlay(2);
      var flashTimer:Timer = new Timer(2000,8);
      flashTimer.addEventListener(TimerEvent.TIMER, onTime);
      flashTimer.start();
      var frame:int = 2;
      function onTime(evt:TimerEvent):void{
       slider_mc.gotoAndPlay(frame);
       slider_mc.stop();
       frame ++; 
       if(frame == 3){zoomIn.slider_mc.tickMark_mc.gotoAndStop(1);}   // line 136
       if(frame == 5){zoomIn.slider_mc.oval1_mc.gotoAndStop(1);}        // line 137
       if(frame == 7){zoomIn.slider_mc.oval2_mc.gotoAndStop(1);}        // line 138

  • Dynamically changing elements in an array of menu ring controls

    I have an array (32 rows, 5 columns) of menu ring controls.  When a menu selection is made in the first column of any given row, the contents of the menu ring for the subsequent columns (same row) may change.  If this is possible, how would you do it?  Thanks.
    Solved!
    Go to Solution.

    jschichl wrote:
    For example, if I had a menu ring of 1,2,3,4.  I want to write some logic that says when 4 is selected, then menu ring in the next row changes to 5,6,7,8.
    A ring is just a number as far as LabVIEW is concerned, so the underlying cluster need only store numbers, not rings.
    In the example I posted in a linked thread, where controls are moved around on top of a table, you need only one ring control. Each time you show that ring, you can assign a new set of strings and values to it, using the Strings and Values property. You can decide what set of strings to show based on the existing data in the cluster, which will get updated each time you change the value in a cell of the table. Does that make sense? I don't have time right now to put together a more detailed example than what I've already uploaded in other threads, and it's only a small change to that.
    You update the menu ring at the time the user wants to select a value from it, not at the time the user changes the value that determines what set of menu items to show.

  • Is it possible to change row colors on array fields orscroll lists?

    I need to create a list field that will allow me to dynamically change the
    fillColor and/or penColor attributes of individual rows. (I just want to
    highlight the rows, and those seem to be the obvious attributes...) It
    appears you can't do that on scroll lists (the elements are list elements,
    and don't have those attributes) and I can't figure out how to do it on an
    array field either. Any ideas for how to accomplish this?
    -Martin ([email protected])

    FreshWebmuse,
    Version 2 of iCal has the "Group Calendar" feature. It was released as part of Mac OS X v10.4, and if you really want/need that feature you will have to upgrade to Tiger.
    ;~)

  • Segfault using char pointer array

    Hi,
    My project was just migrated to a SUN M9000 server running Solaris 10 with Sun Studio 12.1. Here is the cc -V output:
    Sun C 5.10 SunOS_sparc 2009/06/03
    Here is a simple example of code to demonstrate the problem. The compile command used is:
    cc -g -m64 filename.c -o filename
    #include <stdio.h>
    #include <string.h>
    int main(int argc, char **argv)
    char *statusMsg[5] = {
    "0 ",
    "1 ",
    "2 ",
    "3 ",
    "4 " };
    printf("Hello %s\n",statusMsg[3]);
    sprintf(statusMsg[3],"%s","new3");
    printf("Hello %s\n",statusMsg[3]);
    return(0);
    Output is:
    Hello 3
    Segmentation Fault
    I know it crashes on the sprintf.
    dbx output:
    dbx crash_dummy
    Reading crash_dummy
    Reading ld.so.1
    Reading libc.so.1
    (dbx) run
    Running: crash_dummy
    (process id 9169)
    Reading libc_psr.so.1
    Hello 3
    signal SEGV (access to address exceeded protections) in _ndoprnt at 0xffffffff7f3ac948
    0xffffffff7f3ac948: _ndoprnt+0x295c:    stb      %o4, [%o2]
    Current function is main
    17 sprintf(statusMsg[3],"%s","new3");
    (dbx) where
    [1] _ndoprnt(0x1000009aa, 0xffffffff7ffff658, 0x7ffffffefffff62f, 0x1000009b4, 0x1000009b0, 0xffffffff7ffff460), at 0xffffffff7f3ac948
    [2] sprintf(0x1000009d0, 0x7fffffff, 0x7ffffc00, 0xffffffff7f54962c, 0xffffffff7f53e000, 0xa), at 0xffffffff7f3ae024
    =>[3] main(argc = 1, argv = 0xffffffff7ffff768), line 17 in "crash_dummy.c"
    I think it's a bug in libc but I could be wrong. Any help will be appreciated.

    I had forgotten about the problem of literal strings being const. Your code has two bugs, and if it ever worked, it worked only by accident.
    1. Attempting to overwrite a literal string.
    2. Writing beyond the end of an array.
    As poster rajp pointed out, you can fix the first problem by compiling with the option -features=no%conststrings. This is not a general solution, but will work with Studio compilers.
    The second problem still needs to be addressed. As an implementation detail, Studio compilers in 64-bit mode allocate a literal string on an 8-byte boundary, and allocate the literal strings that initialize the array consecutively. By accident, there are a few padding bytes between the literal strings, allowing you to write extra characters to all but the last of the literal strings. (By another accident, there might be padding after the last literal string.)
    To see the bug in action, try writing beyond the accidental padding by writing "new4567890" instead of "new3":
    % cat z.c
    #include <stdio.h>
    #include <string.h>
    #define SIZE 5
    int main(int argc, char **argv)
        char *statusMsg[SIZE] = {
            "0 ",
            "1 ",
            "2 ",
            "3 ",
            "4 " };
        printf("Hello %s\n",statusMsg[3]);
        printf("Hello %s\n",statusMsg[4]);
        sprintf(statusMsg[3],"%s","new4567890");
        int i;
        for( i=0; i < SIZE; ++i )
            printf("Hello %s\n",statusMsg);
    return(0);
    % cc -m64 -features=no%conststrings z.c
    % ./a.out
    Hello 3
    Hello 4
    Hello 0
    Hello 1
    Hello 2
    Hello new4567890
    Hello 90
    Notice how the last string was clobbered.
    In 32-bit mode, literal strings are allocated on 4-byte boundaries, allowing for even more interesting results. I added an unrelated array of one string, "test", then overwrote statusMsg[3] as before. This time, it clobbers not only statusMsg[4], but "test" as well:#include <stdio.h>
    #include <string.h>
    #define SIZE 5
    int main(int argc, char **argv)
    char *statusMsg[SIZE] = {
    "0 ",
    "1 ",
    "2 ",
    "3 ",
    "4 " };
    char *test[1] = { "test" };
    printf("Hello %s\n",statusMsg[3]);
    printf("Hello %s\n",statusMsg[4]);
    printf("Hello %s\n",test[0]);
    sprintf(statusMsg[3],"%s","new4567890");
    int i;
    for( i=0; i < SIZE; ++i )
    printf("Hello %s\n",statusMsg[i]);
    printf("Hello %s\n",test[0]);
    return(0);
    213% cc -m32 -features=no%conststrings z.c
    214% a.out
    Hello 3
    Hello 4
    Hello test
    Hello 0
    Hello 1
    Hello 2
    Hello new4567890
    Hello 567890
    Hello 90

  • Changing a char-string into decimal

    i have a problem:
    over my serial connection i just get strings in char but i need decimal numbers!
    can you help me!
    thx wiesi

    What do you mean "a normal number"? This is a number, 97, and it's inside an array. What do you expect this number to be? To extract it from the array you have various options, from using an index array function to using an auto indexed for loop.
    If your problem is with using the array, I suggest you read the LabVIEW user manual. Also, try searching this site and google for LabVIEW tutorials. Here is one you can start with. You can also contact your local NI office and join one of their courses.
    In addition, I suggest you read the LabVIEW style guide.
    Try to take over the world!

  • Variably Change a 2-D Array name

    Hi Everyone,
    So I have this VI that I had created and someone on here helped vamp it up big time. Thanks again for that. I have run into a snag with my program. So I have this VI that takes in arrays and places them in an xml file. I am using teststand to control a SigGen, PowerMeter, and a switch matrix so I can take a whole bunch of array measurements and place them into a singke xml file. My problem is that my xml file (when the test is completed) will have about 200 or more arrays in it. So I was hoping that I could make the 2-D array name into a variable so I can make each array unique in my xml file. That way I can eventually create another VI that takes the xml file and display the desired array. Does anyone know how to make the 2-D array name into a variable so I can change it to what I want from teststand? My VI is attached below.
    Thanks,
    dlovell
    Solved!
    Go to Solution.
    Attachments:
    Write to XML.vi ‏19 KB

    Hey Taki,
    So I understand now where you are coming from. Did your VI (the picture you posted) work? I can't get the 2D-Array to change to my Var_Name (my input name)... Below is my VI that I made look like your picture.
    Thanks,
    dlovell
    Attachments:
    Write to XML Test.vi ‏21 KB

Maybe you are looking for