Replace characters in a string

Hi,
I need to replace all occurrences of control characters except space,newline,tabs in a string . I can give a replace statement for each of these characters but I want to avoid this by making use of regular expressions. Can anyone help me in this regard.
I tried using the following replace statements with regular expression, but i am not getting the required results:
replace all occurrences of REGEX '[[:cntrl:]]' in lv_char with space replacement count lv_count_r.
---> this replaces even the spaces
replace all occurrences of REGEX '[[:cntrl:]][^[:space:]]' in lv_char with space replacement count lv_count_r.
--> this replaced even some alpha numeric characters
Thanks and Regards,
Shankar

is there anyway to do this without using regular
expressions.. regular expressions are the last
solution for me..Remember that you can never really replace the characters of a String. Strings are immutable. Once created they cannot change.

Similar Messages

  • Problem in replacing characters of a string ?

    Hello everybody,
    I want to replace a few characters with their corresponding unicode codepoint values.
    I have a userdefined method that gets the unicode codepoint value for a character.
    1. I want to know how to replace the characters and have the replaced string after the comparision is over in the for loop in my main.
    Currently , i am able to replace , but i am not able to have the replacements done in a single variable.
    The output of the code is
    e\u3006ame
    ena\u3005e
    But i want the output i require is,
    e\u3006a\u3005e
    Please offer some help in this regard
    import java.io.*;
    class Read1
         public static void main(String s[])
             String rp,snd;
             String tmp="ename";
             for(int i=0;i<tmp.length();i++)
                 snd=getCodepoint(tmp.charAt(i));
                 if(snd!=null)
                    rp=replace(tmp,String.valueOf(tmp.charAt(i)),"\\u"+snd);
                    System.out.println(rp);
    public static String replace(String source, String pattern, String replace)
         if (source!=null)
             final int len = pattern.length();
             StringBuffer sb = new StringBuffer();
             int found = -1;
             int start = 0;
             while( (found = source.indexOf(pattern, start) ) != -1)
                 sb.append(source.substring(start, found));
                 sb.append(replace);
                 start = found + len;
             sb.append(source.substring(start));
             return sb.toString();
         else return "";
    ...,Any help in this regard would be useful
    Thanks
    khurram

    This manual replacement thingy reminds me of quite an old technique, when
    64KB of memory was considered enough for 20 users (at the same time that is!)
    Suppose you have a buffer of, say, n characters. Starting at location i, a region
    of chars have to be swapped with bytes starting at location j >= i+l_i; the lengths
    of the two regions are l_i and l_j respectively.
    Suppose the following method is available:public void reverse(char[] buffer, int f, int l_f) {
       for (int t= f+l_f; --t > f; f++) {
          char tmp=buffer[f]; buffer[f]= buffer[t]; buffer[t]= tmp;
    }i.e. the above method reverses a region of characters, starting at position f
    with length l_f. Given this simple method, the original problem can be solved
    using the following simple sequence:reverse(buffer, i, j+l_j);
    reverse(buffer, i, l_j);
    reverse(buffer, i+l_j, j-i-l_i);
    reverse(buffer, j+l_j-l_i, l_i);Of course, when replacing characters we don't need the last reversal.
    kind regards,
    Jos (dinosaurus)

  • Replacing characters in a string

    I have an application where a user can enter information into a webform. I'm using JSP, but of course the backend there is a Java function also.
    I am trying to write a function which will replace when the user hits enter with a <br> (break tag).
    Right now it's a complicated, messy loop to look at each character and it has many flaws.
    Is there a "replace" function that will do this for me?
    However, I don't think in a webpage form it transfers the \n end of line characters.

    Nope compiler error
    symbol : method replaceAll (java.lang.String,java.lang.String)
    location: class java.lang.String
    return (txt.replaceAll("\n","<br>"));

  • Replacing characters in a string - URGENT!

    Hi guys
    I have a string - 003452.jpg.xml
    I want to remove the '.jpg'
    How do I do this ... I was using :
    String image1 = 002452.jpg.xml;
    String newString = image1.replace ( '.jpg',' ' );
    What am i doing wrong???
    thanks

    The replace method takes characters as its arguments not strings. If you files will always be in that format you can do something like:
    In j2se 1.4 a replace based on regular expressions was added so you could use:
    String image1 = "002452.jpg.xml";
    String newString = image1.replaceAll ("\\.jpg", "" );

  • Search and replace characters in a string

    I am very new to Sharepoint and need your help.  I have set up a calculated column in a sharepoint list that combines a IT release number to its Release title.  The list is set to appear on a calendar plus web part.  The idea is to show
    the title and release number of all deployments going to the field on a particular day.  The issue is that the release number has a bunch of zero's in it that I do not need to be displayed.  For example a release number could be "RND000000123456". 
    I need to parse out "D000000" so only "RN123456" along with its title show up on the calendar.  Please help!!

    Go here and search for "Remove characters":
    http://msdn.microsoft.com/en-us/library/office/bb862071(v=office.14).aspx
    From that page:
    Remove characters from text
    To remove characters from text, use the LEN, LEFT, and RIGHT functions.
    Column1
    Formula
    Description (possible result)
    Vitamin A
    =LEFT([Column1],LEN([Column1])-2)
    Returns 7 (9-2) characters, starting from left (Vitamin)
    Vitamin B1
    =RIGHT([Column1], LEN([Column1])-8)
    Returns 2 (10-8) characters, starting from right (B1)
    You could also try the REPLACE function:
    http://office.microsoft.com/en-us/windows-sharepoint-services-help/replace-function-HA001161055.aspx
    Brandon Atkinson
    Blog: http://sharepointbrandon.com

  • Need help in replacing special characters in a string

    Hi,
    please let me know the best way to replace all the special characters in a string with space.
    other than alphabets and numbers
    with regards.
    sumanth.

    please let me know the best way to replace all the special characters in a string with space.
    other than alphabets and numbers
    >
    Sumanth Nag Kristam wrote:
    > actually i need to replace hexa decimal char 0X1A in a string.... that is 'substitue' as per the chart
    > any pointers....
    >
    > chk the link for the ASCII codes
    > http://www.techonthenet.com/ascii/chart.php
    But in Hexa decimal value there is no special characters?

  • Replace multiple characters in a string

    Hi, I have some string fields that contain special characters such as ô and û and I want to replace them with ō and ū, and their upper case equivalents as well. How do I write a single formula that would find any of these characters in a string and replace them?
    Thanks,
    Will

    replace(replace(replace(replace(x,'ô','ō'),'û','ū'),'Ô','Ö'),'Û','Ü');
    where x is the string field.  I suggest using the unicodes rather than the actual character.  I do not think that I have the correct uppercase characters.  Please ensure that they are correct in your formula.

  • Replacing characters in a specific region of a String?

    I would like to change characters in a specific region of String.
    For example... change String from "leone24" to "leone31".
    I am not looking to change the occurance of 24 to 31 but the region of 5 to 6, in the above String, from 24 to 31. The characters in this region of the String will vary but the region will always be the position of characters that I want to change in the String.
    Thanks in advance,
    D

    This can be easily done with a StringBuffer:StringBuffer sb = new StringBuffer("leone24");
    sb.replace(5,7,"31");
    String newString = sb.toString();

  • VBA Word Find and Replace characters but excluding certain characters

    I am trying to write VBA code in Word that I will eventually run from a VBA Excel module. The aim of the project is to find specific strings in the open Word document that have length of either one or two characters and are of a certain format, and replace
    them with other strings in the same format. This is to do with transposing (i.e. changing the musical key) of chord symbols in a songsheet in Word. The Find and Replace strings are contained in ranges in an Excel workbook, which is why I want to eventually
    run the code from Excel. I'm much more experienced in writing VBA code in Excel than in Word, and I'm fairly confident with transferring the 'Word VBA' code into an Excel module.
    At the moment I'm trying out code entirely in Word, and I've come across a stumbling block. For example, I want it to Find "A" and replace with "B",
    BUT only if the "A" is NOT followed by "#" (sharp) or "b" (flat).
    Here is the code I've got in Word VBA, which I obtained by editing code produced by the recorder:
    Sub F_R()
    'Find text must have specific font
    With Selection.Find.Font
    .Bold = True
    .Underline = wdUnderlineWords
    .Superscript = False
    .Subscript = False
    End With
    'Replacement text must have specific font
    With Selection.Find.Replacement.Font
    .Bold = True
    .Underline = wdUnderlineWords
    .Superscript = False
    .Subscript = False
    End With
    'Find & Replace strings
    With Selection.Find
    .Text = "A" 'hard-coded here for testing, but this will
    'eventually be referenced to a cell in Excel
    .Replacement.Text = "B" 'hard-coded here for testing, but this will
    'eventually be referenced to a cell in Excel
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = True
    .MatchWholeWord = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    For the Find & Replace section I want to do something like:
    With Selection.Find
    .Text = "A"
    .Text <> "A#"
    .Text <> "Ab"
    .Replacement.Text = "B"
    End With
    - but this produces a syntax error, presumably because you can have only one .Text line (or it won't accept <>?)
    I tried adopting the way of excluding chars when using the Like operator, and while it compiles, it will not replace
    any "A":
    With Selection.Find
    .Text = "A[!b#]"
    .Replacement.Text = "B"
    End With
    I suspect that I'm going to have to change tack completely in the way I'm doing this. Do you have any suggestions, please?
    The chord names/symbols are preceded/succeeded by either spaces or paragraph returns and can look like these, for example (all Font Bold and Underlined words only):
    C<sup>7</sup>
    Dm<sup>7</sup>
    Eb<sup>-5</sup>
    Bb<sup>+11</sup>
    F#m<sup>7</sup>
    i.e. [ABCDEFG][b # | optional][m |optional][- + | superscript, optional][2 3
    5 6 7 9 11 13 | superscript, optional]
    The crux of my problem is that the note A should be treated as entirely distinct from Ab or A# (and similar for other flattened/sharpened notes).
    Sorry for long post.

    Hi Ian,
    It is not easy to find Microsoft forums. However this forum is for the Visual Studio Net version. 
    Try this forum for VBA.
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=isvvba
    Success
    Cor

  • How to count number of repeated characters in a String

    I have a String.... 10022002202222.
    I need to know how many 2's are there in the string... here the string contains eight 2's..
    Thanks in advance..

    it is workingYes, but... attention to surprises...
    SQL> var v1 varchar2(1000);
    SQL> exec :v1 := 'How to count the number of occurences of a characters in a string';
    PL/SQL procedure successfully completed.
    SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
    LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
                                       6
    SQL> exec :v1 := 'cccccc';
    PL/SQL procedure successfully completed.
    SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
    LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
    SQL> select length(:v1) - nvl(length(replace(:v1,'c')),0) from dual;
    LENGTH(:V1)-NVL(LENGTH(REPLACE(:V1,'C')),0)
                                              6
    SQL>

  • Removing non-alpha-numeric characters from a string

    How can I remove all non-alpha-numeric characters from a string? (i.e. only alpha-numerics should remain in the string).

    Or even without a loop ?
    Extract from the help for the Search and Replace String function :
    Right-click the Search and Replace String function and select Regular Expression from the shortcut menu to configure the function for advanced regular expression searches and partial match substitution in the replacement string.
    Extract from the for the advanced search options :
    [a-zA-Z0-9] matches any lowercase or uppercase letter or any digit. You also can use a character class to match any character not in a given set by adding a caret (^) to the beginning of the class. For example [^a-zA-Z0-9] matches any character that is not a lowercase or uppercase letter and also not a digit.
    Message Edité par JB le 05-06-2008 01:49 PM
    Attachments:
    Example_VI_BD4.png ‏2 KB

  • Count of characters in a string

    Hi all,
    Is there any way to find the repeating characters in the string like 'L' in the example Hello ..
    Thanks in advance,
    Nalla !
    Message was edited by: Nalla
    Nalla (Nallasivam)

    test@ORA10G>
    test@ORA10G> with t as (
      2    select 'hello' as str from dual union all
      3    select 'abracadabra' from dual union all
      4    select 'the quick brown fox jumps over the lazy dog' from dual union all
      5    select 'abcdefghijklmnopqrstuvwxyz' from dual union all
      6    select 'facetious' from dual)
      7  --
      8  select
      9    str
    10  from t
    11  where (
    12    length(str) - length(replace(lower(str),'a')) > 1 or
    13    length(str) - length(replace(lower(str),'b')) > 1 or
    14    length(str) - length(replace(lower(str),'c')) > 1 or
    15    length(str) - length(replace(lower(str),'d')) > 1 or
    16    length(str) - length(replace(lower(str),'e')) > 1 or
    17    length(str) - length(replace(lower(str),'f')) > 1 or
    18    length(str) - length(replace(lower(str),'g')) > 1 or
    19    length(str) - length(replace(lower(str),'h')) > 1 or
    20    length(str) - length(replace(lower(str),'i')) > 1 or
    21    length(str) - length(replace(lower(str),'j')) > 1 or
    22    length(str) - length(replace(lower(str),'k')) > 1 or
    23    length(str) - length(replace(lower(str),'l')) > 1 or
    24    length(str) - length(replace(lower(str),'m')) > 1 or
    25    length(str) - length(replace(lower(str),'n')) > 1 or
    26    length(str) - length(replace(lower(str),'o')) > 1 or
    27    length(str) - length(replace(lower(str),'p')) > 1 or
    28    length(str) - length(replace(lower(str),'q')) > 1 or
    29    length(str) - length(replace(lower(str),'r')) > 1 or
    30    length(str) - length(replace(lower(str),'s')) > 1 or
    31    length(str) - length(replace(lower(str),'t')) > 1 or
    32    length(str) - length(replace(lower(str),'u')) > 1 or
    33    length(str) - length(replace(lower(str),'v')) > 1 or
    34    length(str) - length(replace(lower(str),'w')) > 1 or
    35    length(str) - length(replace(lower(str),'x')) > 1 or
    36    length(str) - length(replace(lower(str),'y')) > 1 or
    37    length(str) - length(replace(lower(str),'z')) > 1
    38  );
    STR
    hello
    abracadabra
    the quick brown fox jumps over the lazy dog
    3 rows selected.
    test@ORA10G>
    test@ORA10G>pratz

  • Is there a function to check a list of characters in a string?

    is there a function to check a list of characters in a string?

    You need to create a vi. Find attached a vi that you can use. In the vi, if the number of match occurrence is zero, that indicates no match otherwise it will return the number of matches in the supply string. The vi is a modified version of Search String and Replace - General
    Attachments:
    Search_String_and_Count_Match.vi ‏17 KB

  • Lua function to replace metatags in a string?

    (Maybe this is a recipe request for the new cookbook site.)
    I'd like a function that, given a string and a LrPhoto, will search and replace tags in the string with metadata from the photo. So, given a string 'The title of this photo is {{title}}', it would return a string where {{title}} has been replaced with the LrPhoto.getRawMetadata('title') (or maybe getFormattedMetadata). I'm sure it's been written more than once. Is there one out there to be shared before I write my own?
    db

    I spent the time on this myself and don't know why I bothered asking, it was so simple. Here's what I did. First, a general-purpose function to replace any token in a string with values from a table:
    -- replace any string of characters in a string that are surrounded by curly
    -- braces (e.g. {foo}) with the value in the table corresponding to 'foo'.
    -- will replace all tokens in braces if there are more than one
    function DFB.replaceTokens( tokenTable, str )
        return str:gsub( '{(.-)}', function( token ) return tokenTable[token] end )
    end
    Then, if you want to do this with a photo's metadata, just pass the table that's returned from getRaw/FormattedMetadata:
    line = DFB.replaceTokens(  photo:getFormattedMetadata( nil ) , line )
    So if line starts out with "my caption is {caption}" and the photo's caption is 'My Photo Caption', the result is "my caption is My Photo Caption".
    I use this in a simple templating system that reads an HTML template from a file and does this for each line as it reads/writes it. Works well.

  • Manipulating single characters inside a string?

    Hello CF Experts,
    I feel a little stupid having to ask this, but I might be suffering from mental block:
    I need to manipulate single characters inside a string. Lets say I have a string "-----" (5 hyphens) and
    I want to replace the hyphen at position #pos# with "X".
    I tried using the Mid() function, but that apparently is read-only:
         <cfset Mid(string,#pos#,1) = "X">   
    results in an error.
    Of course I can do string concatenation like
         <cfset string = Mid(string,1,#pos#-1) & "X" & Mid(string,#pos#+1,Len(string)-#pos#)
    or use the Insert/RemoveChars functions:
         <cfset string = Insert("X",string,#pos#-1)>
         <cfset string = RemoveChars(string,#pos#+1,1)>
    but this seems awfully awkward.
    There must be a more elegant solution. Any hints?
    Regards, Richard

    Strings are immutable, so one can't "edit" one, all one can do is create a new one based on an existing one.  So your insert() / removechars() approach is fine.  Or one could use left() & mid() (or right()), or replace() or... all variations on a fairly similar theme.
    (http://en.wikipedia.org/wiki/Immutable_object#Java)
    Adam

Maybe you are looking for

  • Service Order Creation from a Repair Order - Reg

    Hi, I have a situation where a batch of 100 Pieces of a serialized Serviceable Material has been delivered by a Customer. I have to carry out repair and treat each piece as unique. i.e., a Job Order for each Piece of the Material. I created a Repair

  • Blank records

    I have a registration form, and when I create test accounts, all that is being put into the record's fields are 0's.  I go to register again with an already registered username, and it says that the username is already in use.  how can this be?  are

  • 2005 PowerBook G4 12"

    I have a circa 2005 PowerBook G4 12" laptop, that I would love to use for my 7 yr daughter, but IU can't get any flash sites to run, and trying to update software but it will not install. It this a lost cause or what am I missing? Is this machine jus

  • Reg:finding out the function module to manager of organization unit

    Hi Experts, Is there any function module for finding out the Manager to organization unit.

  • Graphic problem with Final cut pro X

    Hello Since some days I have graphical problems, it seems it is related to final cut pro X (10.0.8), all other programms are running well. When I import events to my project the graphic is ok: After modification, example: here stabilization on, I hav