Replace char on String

Hi All,
String strValue = "ABC TPT 0694";
My String is as shown above, I am looking for a way to replace char at byte 6 (position 6) with another Char in String.
For example at location 6 it is "T" I want to replace it with char "O". can any one tell me how to do this

String strValue = "ABC TPT 0694";
char[] chars = strValue.toCharArray();
chars[5] = 'O';
strValue = String.valueOf(chars);

Similar Messages

  • Replacing chars in strings

    Here is the situation:
    int x=4
    char letter1='Z'
    String word1="blah blah"
    /code]
    I was wonering if the was an easy way of replacing a character in a string with another at a ceratin point in the string. In this case, I want a string that would say "blahZblah". Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Sure
    int x=4
    char letter1='Z'
    String word1="blah blah"
    [String word2 = word1.substring(0,x) + letter1 + word.substring(x + 1)[/b]

  • Replace " from the string

    Hi,  I am not able to remove " (double quotes) from a sting.
    I am using replace function in webi but getting error.
    example sting: Yellow stone"discovery"
    i have tried like this: =replace([varible];""";"")  but getting error. can anybody help me in removing the " from sting.
    Thanks.

    Description
    Replaces part of a string with another string
    Function Group
    Character
    Syntax
    string Replace(string input_string; string string_to_replace; string replace_with)
    EX:=Replace ([[variable]]; Char(34) ;"")
    Input
    input_string                     The input string 
    string_to_replace             The string within input_string to be replaced 
    replace_with                    The string to replace string_to_replace with. 
    Output
    The string with the part replaced
    Example
    Replace ("New YORK";"ORK";"ork") returns "New York"
    All the best,
    Praveen

  • ASCII character/string processing and performance - char[] versus String?

    Hello everyone
    I am relative novice to Java, I have procedural C programming background.
    I am reading many very large (many GB) comma/double-quote separated ASCII CSV text files and performing various kinds of pre-processing on them, prior to loading into the database.
    I am using Java7 (the latest) and using NIO.2.
    The IO performance is fine.
    My question is regarding performance of using char[i] arrays versus Strings and StringBuilder classes using charAt() methods.
    I read a file, one line/record at a time and then I process it. The regex is not an option (too slow and can not handle all cases I need to cover).
    I noticed that accessing a single character of a given String (or StringBuilder too) class using String.charAt(i) methods is several times (5 times+?) slower than referring to a char of an array with index.
    My question: is this correct observation re charAt() versus char[i] performance difference or am I doing something wrong in case of a String class?
    What is the best way (performance) to process character strings inside Java if I need to process them one character at a time ?
    Is there another approach that I should consider?
    Many thanks in advance

    >
    Once I took that String.length() method out of the 'for loop' and used integer length local variable, as you have in your code, the performance is very close between array of char and String charAt() approaches.
    >
    You are still worrying about something that is irrevelant in the greater scheme of things.
    It doesn't matter how fast the CPU processing of the data is if it is faster than you can write the data to the sink. The process is:
    1. read data into memory
    2. manipulate that data
    3. write data to a sink (database, file, network)
    The reading and writing of the data are going to be tens of thousands of times slower than any CPU you will be using. That read/write part of the process is the limiting factor of your throughput; not the CPU manipulation of step #2.
    Step #2 can only go as fast as steps #1 and #3 permit.
    Like I said above:
    >
    The best 'file to database' performance you could hope to achieve would be loading simple, 'known to be clean', record of a file into ONE table column defined, perhaps, as VARCHAR2(1000); that is, with NO processing of the record at all to determine column boundaries.
    That performance would be the standard you would measure all others against and would typically be in the hundreds of thousands or millions of records per minute.
    What you would find is that you can perform one heck of a lot of processing on each record without slowing that 'read and load' process down at all.
    >
    Regardless of the sink (DB, file, network) when you are designing data transport services you need to identify the 'slowest' parts. Those are the 'weak links' in the data chain. Once you have identified and tuned those parts the performance of any other step merely needs to be 'slightly' better to avoid becoming a bottleneck.
    That CPU part for step #2 is only rarely, if every the problem. Don't even consider it for specialized tuning until you demonstrate that it is needed.
    Besides, if your code is properly designed and modularized you should be able to 'plug n play' different parse and transform components after the framework is complete and in the performance test stage.
    >
    The only thing that is fixed is that all input files are ASCII (not Unicode) characters in range of 'space' to '~' (decimal 32-126) or common control characters like CR,LF,etc.
    >
    Then you could use byte arrays and byte processing to determine the record boundaries even if you then use String processing for the rest of the manipulation.
    That is what my framework does. You define the character set of the file and a 'set' of allowable record delimiters as Strings in that character set. There can be multiple possible record delimiters and each one can be multi-character (e.g. you can use 'XyZ' if you want.
    The delimiter set is converted to byte arrays and the file is read using RandomAccessFile and double-buffering and a multiple mark/reset functionality. The buffers are then searched for one of the delimiter byte arrays and the location of the delimiter is saved. The resulting byte array is then saved as a 'physical record'.
    Those 'physical records' are then processed to create 'logical records'. The distinction is due to possible embedded record delimiters as you mentioned. One logical record might appear as two physical records if a field has an embedded record delimiter. That is resolved easily since each logical record in the file MUST have the same number of fields.
    So a record with an embedded delimiter will have few fields than required meaning it needs to be combined with one, or more of the following records.
    >
    My files have no metadata, some are comma delimited and some comma and double quote delimited together, to protect the embedded commas inside columns.
    >
    I didn't mean the files themselves needed to contain metadata. I just meant that YOU need to know what metadata to use. For example you need to know that there should ultimately be 10 fields for each record. The file itself may have fewer physical fields due to TRAILING NULLCOS whereby all consecutive NULL fields at the of a record do not need to be present.
    >
    The number of columns in a file is variable and each line in any one file can have a different number of columns. Ragged columns.
    There may be repeated null columns in any like ,,, or "","","" or any combination of the above.
    There may also be spaces between delimiters.
    The files may be UNIX/Linux terminated or Windows Server terminated (CR/LF or CR or LF).
    >
    All of those are basic requirements and none of them present any real issue or problem.
    >
    To make it even harder, there may be embedded LF characters inside the double quoted columns too, which need to be caught and weeded out.
    >
    That only makes it 'harder' in the sense that virtually NONE of the standard software available for processing delimited files take that into account. There have been some attempts (you can find them on the net) for using various 'escaping' techniques to escape those characters where they occur but none of them ever caught on and I have never found any in widespread use.
    The main reason for that is that the software used to create the files to begin with isn't written to ADD the escape characters but is written on the assumption that they won't be needed.
    That read/write for 'escaped' files has to be done in pairs. You need a writer that can write escapes and a matching reader to read them.
    Even the latest version of Informatica and DataStage cannot export a simple one column table that contains an embedded record delimiter and read it back properly. Those tools simply have NO functionality to let you even TRY to detect that embedded delimiters exist let alone do any about it by escaping those characters. I gave up back in the '90s trying to convince the Informatica folk to add that functionality to their tool. It would be simple to do.
    >
    Some numeric columns will also need processing to handle currency signs and numeric formats that are not valid for the database inpu.
    It does not feel like a job for RegEx (I want to be able to maintain the code and complex Regex is often 'write-only' code that a 9200bpm modem would be proud of!) and I don't think PL/SQL will be any faster or easier than Java for this sort of character based work.
    >
    Actually for 'validating' that a string of characters conforms (or not) to a particular format is an excellent application of regular expressions. Though, as you suggest, the actual parsing of a valid string to extract the data is not well-suited for RegEx. That is more appropriate for a custom format class that implements the proper business rules.
    You are correct that PL/SQL is NOT the language to use for such string parsing. However, Oracle does support Java stored procedures so that could be done in the database. I would only recommend pursuing that approach if you were already needing to perform some substantial data validation or processing the DB to begin with.
    >
    I have no control over format of the incoming files, they are coming from all sorts of legacy systems, many from IBM mainframes or AS/400 series, for example. Others from Solaris and Windows.
    >
    Not a problem. You just need to know what the format is so you can parse it properly.
    >
    Some files will be small, some many GB in size.
    >
    Not really relevant except as it relates to the need to SINK the data at some point. The larger the amount of SOURCE data the sooner you need to SINK it to make room for the rest.
    Unfortunately, the very nature of delimited data with varying record lengths and possible embedded delimiters means that you can't really chunk the file to support parallel read operations effectively.
    You need to focus on designing the proper architecture to create a modular framework of readers, writers, parsers, formatters, etc. Your concern with details about String versus Array are way premature at best.
    My framework has been doing what you are proposing and has been in use for over 20 years by three different major nternational clients. I have never had any issues with the level of detail you have asked about in this thread.
    Throughout is limited by the performance of the SOURCE and the SINK. The processing in-between has NEVER been an issu.
    A modular framework allows you to fine-tune or even replace a component at any time with just 'plug n play'. That is what Interfaces are all about. Any code you write for a parser should be based on an interface contract. That allows you to write the initial code using the simplest possible method and then later if, and ONLY if, that particular module becomes a bottlenect, replace that module with one that is more performant.
    Your intital code should ONLY use standard well-established constructs until there is a demonstrated need for something else. For your use case that means String processing, not byte arrays (except for detecting record boundaries).

  • Delete a char from string ?

    Hi,
    I want to delete a char from string. i used the following function.
    String f = formulla.replace('[','');
    The above function doesnt work as it tells me to put a space or some char in 2nd parameter which i dont want. i just want to delete all occurences of some specific char in a string.
    Any suggestion.
    Thanks alot.

    u can do:
    String before;
    char charToReplace;
    StringBuffer tempBuf = new StringBuffer(before);
    for (int i=0; i<tempBuf.length(); i++)
            if (tempBuf.charAt(i)==charToReplace)
                  tempBuf.deleteCharAt(i);
    String after = tempBuf .toString(); HTH
    Yonatan

  • Replacing chars

    I have a problem with replacing chars. I want to replace the following chars <, > and '
    I've implemented the following code:
    remove(String str) {
        Pattern p = Pattern.compile("[<>']");
        Matcher m = p.matcher(str);
        StringBuffer sb = new StringBuffer();
        boolean result = m.find();
        boolean deletedIllegalChars = false;
        while (result) {
          deletedIllegalChars = true;
          m.appendReplacement(sb, " ");
          result = m.find();
        // Add the last segment of input to the new String
        m.appendTail(sb);
        str = sb.toString();
        return str;
    }The problem now is, that the ' is not replaced after running the method above. What I'm doing wrong?
    P.S.: Maybe my problem doesn't fit to this forum, but I don't found a better place.

    The problem now is, that the ' is not replaced after
    running the method above. What I'm doing wrong?
    It is on my computer, maybe the string doesn't really contain the ascii apostrophe-signle quote but some special "smart quote" or the acute/grave accent symbol. They all look like the similar but aren't the same.
    For instance the preferred character for apostrophe is \u2019 according to the unicode spec. Maybe you want to be replacing it instead/aswell.
    P.S.: Maybe my problem doesn't fit to this forum, but
    I don't found a better place.I think Java Programming and New to Java get most of the miscallaneous posts..

  • Two finger swipe replaces google search string

    MBP with Safari 6.0 experiencing this problem.  Another user was experiencing the issue here:
    http://www.ehmac.ca/mac-iphone-ipad-ipod-help-troubleshooting/99937-safari-two-f inger-swipe-bug-replaces-google-search-string-os-10-7-3-a.html
    I don't know where the bug reports are to follow up on it and I haven't seen any patches for it.  Any advice?  Specifically, I'd like to know how to file the bug (in case I find another) and to follow up on any existing issues.
    TIA,
    Scott

    Is there no place to track the status of the report or see any other outstanding issues so I don't bother filing duplicates?
    Never heard of such a function here. This method gets feedback to the people who count but it is completely behind the scenes. Part of Apple's "cards close to the chest" method of doing pretty much everything. You should have been looking at the "don't expect a response" screen after you hit the submit button on your bug report.
    If there is something that needs clarification, I suspect they will use e-mail to ask for it, but don't stay home waiting!
    Have you read Walter Isaacson's  biography of Steve Jobs? Things like this took on a new--if not satisfying--perspective for me after reading it. So far, it has persisted in their corporate culture in the after-Steve era..

  • How Can I replace newScale Text Strings with Custom Values?

    How Can I replace newScale Text Strings with Custom Values?
    How can I replace newScale text strings with custom values?
    All  newScale text is customizable. Follow the procedure below to change the  value of any text string that appears in RequestCenter online pages.
    Procedure
    1. Find out the String ID of the text string you would like to overwrite by turning on the String ID display:
    a) Navigate to the RequestCenter.ear/config directory.
    b) Open the newscale.properties file and add the following name-value pair at the end of the file:res.format=2
    c) Save the file.
    d) Repeat steps b and c for the RmiConfig.prop and RequestCenter.prop files.
    e) Stop and restart the RequestCenter service.
    f) Log  in to RequestCenter and browse to the page that has the text you want  to overwrite. In front of the text you will now see the String ID.
    g) Note down the String ID's you want to change.
    2. Navigate to the directory: /RequestCenter.ear/RequestCenter.war/WEB-INF/classes/com/newscale/bfw.
    3. Create the following sub-directory: res/resources
    4. Create the following empty text files in the directory you just created:
    RequestCenter_0.properties
    RequestCenter_1.properties
    RequestCenter_2.properties
    RequestCenter_3.properties
    RequestCenter_4.properties
    RequestCenter_5.properties
    RequestCenter_6.properties
    RequestCenter_7.properties
    5. Add the custom text strings to the appropriate  RequestCenter_<Number>.properties file in the following manner  (name-value pair) StringID=YourCustomTextString
    Example: The StringID for "Available Work" in ServiceManager is 699.
    If you wanted to change "Available Work" to "General Inbox", you  would add the following line to the RequestCenter_0.properties file
         699=General Inbox
    Strings are divided into the following files, based on their numeric ID:
    Strings are divided into the following files, based on their numeric ID:
    String ID  File Name
    0 to 999 -> RequestCenter_0.properties
    1000 to 1999 -> RequestCenter_1.properties
    2000 to 2999 -> RequestCenter_2.properties
    3000 to 3999 -> RequestCenter_3.properties
    4000 to 4999 -> RequestCenter_4.properties
    5000 to 5999 -> RequestCenter_5.properties
    6000 to 6999 -> RequestCenter_6.properties
    7000 to 7999 -> RequestCenter_7.properties
    6. Turn off the String ID display by removing (or commenting out) the line "res.format=2" from the newscale.properties, RequestCenter.prop and RmiConfig.prop files
    7. Restart RequestCenter.
    Your customized text should be displayed.

    I've recently come across this information and it was very helpful in changing some of the inline text.
    However, one place that seemed out of reach with this method was the three main buttons on an "Order" page.  Specifically the "Add & Review Order" button was confusing some of our users.
    Through the use of JavaScript we were able to modify the label of this button.  We placed JS in the footer.html file that changes the value of the butt

  • Replace the connection string in Excel MDS file

    I had MDS solution from one SQL Server 2012 to another - SQL Server 2014. I have configured Excel file with connection to MDS. How can I safely to replace the connection string in my Excel MDS file and the tables is not broken?
    from Moscow with money

    Hi,
    Excel is just used to manage data and create new entities and attributes. Why not first publish and close your excel before MDS upgraded to 2014? After the upgrade, reconnect new solution in your excel.
    thanks,
    Jerry

  • What api would I use to get the number of chars in string?

    What api would I use to get the number of chars in string?

    Assuming that you really mean that you want the number of charaters in a String (not string), that would be documented in java.lang.String
    The method is length()

  • I have to generate a 4 char unique string from a long value

    I got a requirment
    I have to generate a 4 char unique string from a long value
    Eeach char can be any of 32 character defined has below.
    private static final char char_map[] = new char[]{'7','2','6','9','5','3','4','8','X','M','G','D','A','E','B','F','C','Q','J','Y','H','U','W','V','S','K','R','L','N','P','Z','T'};
    So for 4 char string the possible combination can be 32 * 32 * 32 * 32 = 1048576
    If any one passes a long value between 0 - 1048576 , it should generate a unique 4 char string.
    Any one with idea will be a great help.

    Well, a long is 64 bits. A char is 16 bits. Once you determine how you want to map the long's bits to your char bits, go google for "java bitwise operators".

  • Replace charcter from string in 46c

    Hi,
    If you could send me code for below scanerio that will be great.
    in 46c i have string '/ABCD/te_12' now i want to replace the '/' with '+'  and '_' with '|', can you tell me how to do this.
    thanks,
    john

    hi check the replace statement... hit F1 on replace and make ur code..
    Basic form
    REPLACE f WITH g INTO h.
    Addition
    ... LENGTH len (length specification for field f )
    Effect
    Replaces the first occurrence of the contents of field f in field h with the contents of field g . All fields are handled in their defined length; this means that closing blanks are not ignored.
    The return code value indicates whether the string f was found in h and replaced by g :
    SY-SUBRC = 0 String replaced.
    SY_SUBRC = 4 String not replaced.
    Example
        DATA FIELD(10).
        MOVE 'ABCB' TO FIELD.
        REPLACE 'B' WITH 'string' INTO FIELD.
    returns:
    FIELD = 'AstringCB', SY-SUBRC = 0
    Note
    The fields f and g in the REPLACE statement should not overlap. Otherwise, the result is undefined.
    Addition
    ... LENGTH len ... (length specification for field f )
    Effect
    Searches for the string f in the field h not in its (full) field length, but in the length len .
    Example
        DATA: PATTERN(5) VALUE 'ABC',
              LEN TYPE I,
              REPL_STRING(5) VALUE '12345',
              FIELD(12) VALUE 'abcdeABCDE'.
        REPLACE PATTERN WITH REPL_STRING
                        INTO FIELD.
    does not change FIELD , since 'ABC ' does not occur in abcdeABCDE ' .
        LEN = STRLEN( PATTERN ).
        REPLACE PATTERN LENGTH LEN
                        WITH REPL_STRING
                        INTO FIELD.

  • Converting chars to strings

    I don't know how to get this thing to work:
    public class TestGrade
    public static void main(String[] args)throws GradeException
      int studentID = 123423;
      char grade;
      String aGrade = new String();
      try
       System.out.println("Student #: " + studentID);
       System.out.println("Enter a letter grade for student: ");
       grade = (char)System.in.read();
       if(grade >= 'A' && grade <= 'F' || grade >= 'f' && grade <= 'f')
        System.out.println("Student ID#: " + studentID + "Grade: " + grade);
        aGrade = grade;
       else
        throw(new GradeException(aGrade));
      catch(GradeException error)
           System.out.println("Test Error: " + error.getMessage ());
    }

    it might help if I tell you where the error is...
       aGrade = grade; generates a rather obvious error. Incompatible types, I don't know how to convert this sucker into a string so I can feed a string into GradeException....

  • Search given string array and replace with another string array using Regex

    Hi All,
    I want to search the given string array and replace with another string array using regex in java
    for example,
    String news = "If you wish to search for any of these characters, they must be preceded by the character to be interpreted"
    String fromValue[] = {"you", "search", "for", "any"}
    String toValue[] = {"me", "dont search", "never", "trip"}
    so the string "you" needs to be converted to "me" i.e you --> me. Similarly
    you --> me
    search --> don't search
    for --> never
    any --> trip
    I want a SINGLE Regular Expression with search and replaces and returns a SINGLE String after replacing all.
    I don't like to iterate one by one and applying regex for each from and to value. Instead i want to iterate the array and form a SINGLE Regulare expression and use to replace the contents of the Entire String.
    One Single regular expression which matches the pattern and solve the issue.
    the output should be as:
    If me wish to don't search never trip etc...,
    Please help me to resolve this.
    Thanks In Advance,
    Kathir

    As stated, no, it can't be done. But that doesn't mean you have to make a separate pass over the input for each word you want to replace. You can employ a regex that matches any word, then use the lower-level Matcher methods to replace the word or not depending on what was matched. Here's an example: import java.util.*;
    import java.util.regex.*;
    public class Test
      static final List<String> oldWords =
          Arrays.asList("you", "search", "for", "any");
      static final List<String> newWords =
          Arrays.asList("me", "dont search", "never", "trip");
      public static void main(String[] args) throws Exception
        String str = "If you wish to search for any of these characters, "
            + "they must be preceded by the character to be interpreted";
        System.out.println(doReplace(str));
      public static String doReplace(String str)
        Pattern p = Pattern.compile("\\b\\w+\\b");
        Matcher m = p.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (m.find())
          int pos = oldWords.indexOf(m.group());
          if (pos > -1)
            m.appendReplacement(sb, "");
            sb.append(newWords.get(pos));
        m.appendTail(sb);
        return sb.toString();
    } This is just a demonstration of the technique; a real-world solution would require a more complicated regex, and I would probably use a Map instead of the two Lists (or arrays).

  • How to replace in a String

    I really want to know how to replace " in a String with replaceAll()
    I want to replace " with \"
    Unortunately I am not able to do it with :
    xml = xml.replaceAll("\"", "\\\"");Can u please suggest something
    thanks

    public class Test {
    public static void main(String[] args) {
       System.out.println("abc>def".replaceAll(">","\"+"));
    }Output:
    abc"+def

Maybe you are looking for

  • Time Machine does not cope well with nearly-full disk

    Although Time Machine is supposed to delete old backups when the disk fills up, under some circumstances it does not cope well with a disk-full condition. Hardware: iMac (mid 2007) OS: Mac OS X version 10.6.8 (Snow Leopard) Processor: 2.8 GHz Intel C

  • Sharing Folders in Adobe Creative Cloud

    How do you share a folder on the Adobe Creative Cloud?  There are several references in the knowledge base about this functionality being available with the June 17 CC update.  I am unable to find a post about this issue after this date.  Am still un

  • IWDDropDownByKey - Key is shown instead of the value in View

    Hi, we found some strange behaviour when we dynamically generate some IWDDropDownByKey UI-Elements in an IWDTransparentContainer. In IExplorer and Firefox all data looks well. The values in the IWDDropDownByKey-Elements are shown as expected. In one

  • WLAN HDMI connection to TV

    I believe I read somewhere that there is a WLAN-module which can be connected to a Plasma-TV via an HDMI-cable, thus being able to view slideshows from an e.g. iMac in a different room. Does anyone have more info on this topic/module/connection? I us

  • RAID MANAGER for X86?

    I am currently working on a project , in which I am connecting an x86 W1100Z Sun server, running Solaris 10, to an A1000 through using an LM320 Dual SCSI card. The theory is to use SAMBA to share the A1000's file systems across a network consisting o