Replace a String pattern

I have the following string:
String="TVBeginEsternTVEnd
MovieBeginN/AMovieEnd
TVBeginPacificTVEnd
MovieBeginN/AMovieEnd......................"
I need to replace only the contents between TVBegin and TVEnd. The result (If I want the content=Midwest) should look as follow:
String="TVBeginMidwestTVEnd
MovieBeginN/AMovieEnd
TVBeginMidwestTVEnd
MovieBeginN/AMovieEnd......................"
Do you have any suggestions on how to replace the string content?
Thank you very much!

Sheshy,
We can tell you how to do small things, one at a time, all day long. You really need to learn how to read the documentation. Go read the documentation for String, StringBuffer. You can figure it out. Really.

Similar Messages

  • Replace specific string in a file while reading it

    Hi,
    I am kind of an in between learner & intermediate programmer. I am trying to replace a specific string pattern in a file by reading it using BufferedReader & BufferedWriter. I tried it for 2 days. Can anyone give me a piece of code which reads a file line by line and replaces the specific string format with other? I tried replaceAll(regex,replacement). Nothing is working.

    Hi Torajirou,
    Thanks for the code. But, looks like
    . But, looks like it is giving me a static method
    problem. It says a static method should beaccessed
    in a static way(f1.replace in main). Here is the
    code. Can you help me with this?
    import java.io.*;
    public class FileReadWrite1{
    public static void replace(File file, Stringregex,
    String replacement) throws
    FileNotFoundException,IOException {
         if (file == null) {
    throw new IllegalArgumentException("File should
    uld not be null.");
         if (!file.exists()) {
    throw new FileNotFoundException ("File does not
    not exist: " + file);
         if (!file.isFile()) {
    throw new IllegalArgumentException("Should not be
    be a directory: " + file);
         if (!file.canWrite()) {
    throw new IllegalArgumentException("File cannot be
    be written: " + file);
    File tempFile = File.createTempFile("temp",
    mp", "temp");
    BufferedReader reader = new BufferedReader(new
    (new FileReader(file));
    BufferedWriter writer = new BufferedWriter(new
    (new FileWriter(tempFile));
    try{
    while (true) {
    String line = reader.readLine();
    if (line == null) {
    break;
    line = line.replaceAll(regex,replacement);
    writer.write(line);
    writer.newLine();
    writer.close();
    reader.close();
    file.delete();
    tempFile.renameTo(file);
    }catch (Exception e) {
         System.out.println("Exception occured :"+e);
    public static void main(String[] args) {
         FileReadWrite1 f1 = new FileReadWrite1();
         File file = new File("C:\\Temp\\src1.txt");
         String regex = "us.mi.state";
         String replacement = "us.tx.state";
         f1.replace(file,regex,replacement);
    }when I wrote it, I was sober and bored
    now I'm drunk and amused
    god
    did you try and remove the magic "static" keyword ?
    I wrote it static because I didn't refer to any class
    member when I wrote it and that's what I felt
    compelled to do, though I feel nowadays writing
    anyting static suggests some design mistake
    somewhere
    blahblahblahblahblahs/blahblahblahblahblah/blahblahblahblahblahblah
    (forgot a "blah")

  • How to find and replace any string between " "

    Hi everyone,
    Here my sample
    String szTest;
    szTest = "Yellow banana";
    szTest = "Blue monkey";
    szTest = "Red mango";
    szTest is only needed when it's in testing progress. Now I want to put all of that in the /*comment*/ so the released program won't run those code any more (but still keep szTest so I can use it for future develop testing).
    So Here what I want after using the Find and Replace Box:
    //String szTest; //Manual
    /*szTest = "Yellow banana";*/ //use find and replace
    /*szTest = "Blue monkey";*/ //use find and replace
    /*szTest = "Red mango";*/ //use find and replace
    I think I can do this with Regular expressions or Wildcards. But I don't know how to find and replace any string between " and ".
    Find: szTest = " ??Any string?? ";
    Replace with: /*szTest = " ??Any string?? ";*/
    Thanks for reading.

    Hi Nathan.j.Smith,
    Based on your issue, I suggest you can try the Joel's suggestion check your issue again. In addition, I find a MSDN document about how to use the Regex.Replace Method to match a regular expression pattern with a specified replacement string,
    maybe you will get some useful message.
    https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx
    If the above suggestion still could not provide you, could you please tell me what language you use to create the program for finding and replace any string using regular expression so that we will find the correct programming develop forum to support this
    issue?
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • [Forum FAQ] How to find and replace text strings in the shapes in Excel using Windows PowerShell

    Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
    shapes in Excel Object.
    Since the Excel.Application
    is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
    interact with Excel document.
    The figure below is an excel file:
    Figure 1.
    You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
    $text = “text1”,”text2”,”text3”,”text3”
    $Excel 
    = New-Object -ComObject Excel.Application
    $Excel.visible = $true
    $Workbook 
    = $Excel.workbooks.open("d:\shape.xlsx")      
    #Open the excel file
    $Worksheet 
    = $Workbook.Worksheets.Item("shapes")       
    #Open the worksheet named "shapes"
    $shape = $Worksheet.Shapes      
    # Get all the shapes
    $i=0      
    # This number is used to replace the text in sequence as the variable “$text”
    Foreach ($sh in $shape){
    $sh.TextFrame.Characters().text  
    # Get the textbox in the shape
    $sh.TextFrame.Characters().text = 
    $text[$i++]       
    #Change the value of the textbox in the shape one by one
    $WorkBook.Save()              
    #Save workbook in excel
    $WorkBook.Close()             
    #Close workbook in excel
    [void]$excel.quit()           
    #Quit Excel
    Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
    Besides, we can also find the documents about these methods and properties in MSDN:
    Workbook.Worksheets Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
    Worksheet.Shapes Property:
    http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
    Shape.TextFrame Property:
    http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
    TextFrame.Characters Method (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
    Characters.Text Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
    After running the script above, we can see the changes in the figure below:
    Figure 2.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thank you for the information, but does this thread really need to be stuck to the top of the forum?
    If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
    EDIT: I see this is no longer stuck to the top of the forum, thank you.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Find and Replace text string in HTML

    Opps... I hope this forum is not just for Outlook. My Html files reside on my hard-drive. I am looking for VBA code to open specified file names ####File.html and then find and replace text strings within the html for example "####Name" replaced
    with "YYYYY"
    I drive the "####File.html" names and the find and replace text strings from an Excel sheet. I am an artist and this Sub would give me time to paint instead of find and replace text. Thank you!
    [email protected]

    Hello Phil,
    The current forum is for developers and Outlook related programming questions. That's why I'd suggest hiring anybody for developing the code for you. You may find freelancers, for example. Try googling for any freelance-related web sites and asking such
    questions there.
    If you decide to develop an Outlook macro on your own, the
    Getting Started with VBA in Outlook 2010 article is a good place to start from.

  • How to search and replace a string in Excel Shape (textbox) using Powershell.

    I have been asked to write a PS script to search/replace a string when found in Excel Shapes when they are textboxes. I have seen lots of simplistic PS scripts and even I can do a "foreach" loop through all the Shapes on a Sheet and display the
    Name of each Shape. But I have not found a property or method to expose the actual text in a textbox let alone change it.
    I have seen vba script that does this as:  
    Set xWs = Application.ActiveWorkbook.Worksheets(I)
    For Each shp In xWs.Shapes
    xValue = shp.TextFrame.Characters.Text
    shp.TextFrame.Characters.Text = VBA.Replace(xValue, xFindStr, xReplace, 1)
    Next
    In Powershell, shp.TextFrame.Characters.Text is ignored and returns nothing.  It would be nice to know if this is possible in PS and if so, know how to do it and/or get an example to work from.  I would have thought that
    PS and VB would use the same Excel object model but apparently they do not.
    I am using Excel 14.0 and PS 3.
    Any suggestions would be appreciated,
    Michael

    This didn't work for me.  I have the shape object and it shows the textframe property:
    PS C:\> $shape | gm
       TypeName: System.__ComObject#{00024439-0000-0000-c000-000000000046}
    Name                       MemberType Definition
    Apply                      Method     void Apply ()
    CanvasCropBottom           Method     void CanvasCropBottom (float)
    SoftEdge                   Property   SoftEdgeFormat SoftEdge () {get}
    TextEffect                 Property   TextEffectFormat TextEffect () {get}
    TextFrame                  Property   TextFrame TextFrame () {get}
    TextFrame2                 Property   TextFrame2 TextFrame2 () {get}
    ThreeD                     Property   ThreeDFormat ThreeD () {get}
    But trying to access it gives an error:
    PS C:\> $shape.textframe | gm
    gm : You must specify an object for the Get-Member cmdlet.
    At line:1 char:20
    + $shape.textframe | gm
    +                    ~~
        + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
        + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
    PS C:\> $shape.TextFrame.Characters().text="hello"
    You cannot call a method on a null-valued expression.
    At line:1 char:1
    + $shape.TextFrame.Characters().text="hello"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
    I hope this post has helped!

  • Problem in replacing the String in a Fille.

    I need to replace the String in the text file, am able to do it partially.
    I mean, am able to replace it. But there are some discrepancies if the replacement string is of "less" or "more" in length than the existing one.
    I solved it for the replacement string of less size, but am unable to do it for the string of more size.. :(
    The problem am facing is "when the replacement string is larger than the existing one, then the other subsequent line in the file gets overwritten".
    I have used RandomAccessFile class for reading and writing the same file.
    fpointer1 = randomFile.getFilePointer() - strLine.length() - 2;
    strLine1 = strLine;
    int sInd = strLine1.indexOf('\'');
    int eInd = strLine1.indexOf(';');
    String oldStr = strLine1.substring(sInd + 1, eInd - 1);
    strLine1 = StringUtils.replace(strLine1, oldStr, newStr);
    if (oldStr.length() < newStr.length()) {
    int diff = (newStr.length() - oldStr.length()) + 1;
    randomFile.writeBytes("\r\n");
    for (int i = 0; i < diff; i++) {
    randomFile.writeBytes(" ");
    randomFile.seek(fpointer1);
    randomFile.writeBytes(strLine1);
    } else if (oldStr.length() > newStr.length()) {
    randomFile.seek(fpointer1);
    randomFile.writeBytes(strLine1);
    int diff = (oldStr.length() - newStr.length()) + 1;
    for (int i = 0; i < diff - 1; i++) {
    randomFile.writeBytes(" ");
    randomFile.writeBytes("\r\n");
    break;
    }Can u pls help me in resolving this issue???...

    boopathi wrote:
    As u said the overwriting causes the problem, but i managed to resolve for the string of less size.I assume you did this with some padding? That's not exactly a clean solution.
    So thats why am seeking to manage the larger size string to replace without overwriting the sub sequent lines.
    Can you help me in suggesting whether it can be resolved using the getFilePointer() and seek() methods??...No you can't.
    Whether you shorten or lengthen the position where you modify the file, you need to move the remaining bytes back or forward, depending which is the case.
    You managed to solve the first case by printing out padding, so you don't need to move the bytes back, but you can't solve the other case like this. You can lengthen the file and move the remaining bytes forward, but I probably wouldn't bother since a simple Reader-based approach is a lot better and easier to get right.

  • Batch File Search and Replace a String

    I've written a batch file to handle the copying of files.  I'm trying to reduce the number of parameters that I pass to the batch file.
    I want the batch file to perform a string replace on the directory path that is passed as a parameter to the batch file.
    Here is how I run the batch file:
    COPY_FILE.BAT C:\DATA\FTP_DATA\ACME\IN      (I'm passing directory path "C:\DATA\FTP_DATA\ACME\IN" as parameter %1)
    So my batch file will copy a file to the directory path represented by parameter %1.
    But then I want the file copied to a second directory.  I want the batch file to replace string "FTP_DATA" in the directory path with string "FTP_DATA\ARCHIVE"
    I know I could pass this path as a second parameter, but I want to limit the number of parameters so figured I could have the batch file perform a search and replace on string "FTP_DATA".
    After searching the internet, I thought I found the answer by using the following command in the batch file:
    set ARCHIVE_PATH=%1:FTP_DATA=FTP_DATA\ARCHIVE
    But it doesn't perform a search and replace.  It just appends to the directory path with the following result:
    C:\DATA\FTP_DATA\ACME\IN:FTP_DATA=FTP_DATA\ARCHIVE
    What I want is the this:
    C:\DATA\FTP_DATA\ARCHIVE\ACME\IN
    Any suggestions?

    Your syntax is not correct. Example:
    @echo off
    setlocal enableextensions
    set ARCHIVE_PATH=C:\DATA\FTP_DATA\ACME\IN
    echo %ARCHIVE_PATH%
    set ARCHIVE_PATH=%ARCHIVE_PATH:FTP_DATA=FTP_DATA\ARCHIVE%
    echo %ARCHIVE_PATH%
    endlocal
    -- Bill Stewart [Bill_Stewart]

  • Replacing a string of character by another one with emacs

    Hello,
    With Vim, I had something like this in my setup (tex.vim in ftplugin)
    imap <buffer> ... \ldots
    imap <buffer> « \og
    imap <buffer> » \fg
    imap <buffer> " \textquotedblleft
    imap <buffer> ¢ \textquotedblright\
    imap <buffer> € \EUR
    imap <buffer>~ $\sim\
    imap <buffer> // \\
    imap <buffer> /np \newpage
    Currently, I am trying emacs, and would like the same setup. I have searched the web, but with no luck. Indeed, I've just found the following code (and made some modifications to try it) :
    (defun replace-string-pairs-region (start end mylist)
    "Replace string pairs in region."
    (save-restriction
    (narrow-to-region start end)
    (mapc
    (lambda (arg)
    (goto-char (point-min))
    (while (search-forward (car arg) nil t) (replace-match (cadr arg)) )
    ) mylist
    (defun replace-chars (start end)
    "Replace "..." by "\ldots" and other similar chars"
    (interactive "r")
    (replace-string-pairs-region start end '(
    ("..." "\ldots")
    ;("<" "&lt;")
    ;(">" "&gt;")
    But it doesn't work.
    Does anyone know how could I replace "..." by "\ldots" and other things like that with Emacs ?
    Last edited by alexandre (2010-09-28 17:48:50)

    Thank you a lot for your answer, but my problem was not to replace "..." by "\ldots" after typing it, but how could I replace "..." by "\ldots" while I am typing it, just after I finished to push the last dot.
    I have tried to set it up with the abbrev mode, but it seems to work only for words. So for example, if I enter the word such as, say, "arch", then it replace it automatically by "archlinux" after pressing the space key. I won't have to replace the string manually, it does it automatically with the abbreviation mode of Emacs. Here is an example of what I am talking about :
    (abbrev-mode t) ; completion automatique
    (global-set-key (quote [tab]) (quote dabbrev-expand))
    (setq default-abbrev-mode t)
    (define-abbrev-table 'global-abbrev-table '(
    ("..." "\ldots" t)
    ("arch" "archlinux" nil)
    But my problem is, it doesn't work for "...", just for words. Of course, I could do it manually with the shortcut you wrote, but it would be nice to make it work automatically. Is there a way to do so ?
    If you don't understand what I am talking  about, try Vim, copy "imap <buffer> ... \ldots" in your .vimrc, and Vim will replace all "..." by "\ldots" while typing. I am sure I can do it with Emacs, I just don't know how.
    Last edited by alexandre (2010-09-30 12:28:38)

  • Replacing multiple strings for many occurance of single string   in OBIEE a

    Hi,
    I have a requirement like i need to replace a Particular string('_') that occur three times in a string.I need to replace different strings for each occurance of ('_').
    My requirement is like this,
    My string is 'A_B_C_D' and I need to replace first'_' as 'E=' second '_' as 'F=' third '_' as 'G='.
    and the final string should be I=A E=B F=C G=D...
    Can any one help me in the logic or else help me how to use the existing functions in answers.

    Hi,
    We have Replace function in Answers which would replace all occurunces of a particular character with another. To achieve your requirement, you will need to split your string and apply replace function on each part and finally concatenate again.
    For e.g. your string is 'A_B_C_D'
    You need to split into, below
    A_
    B_
    C_
    D
    Apply Replace function to first three parts and then finally concatenate.
    Replace('A_','_','E=') || Replace('B_','_','F=') || Replace('C_','_','G=') || 'D'
    To split the string into parts you may have to use substring and locate functions.
    Refer the below thread too.
    Re: extract a part of a string in a full  string
    Thanks

  • E4X : How to get elements that contain a string pattern in the node name?

    Is there a way to extract children from an XMLList where the node name of a child contains a string pattern?
    For example :
    <record>
         <XblahX/>
         <cow/>
         <YblahY/>
    </record>
    How to get the elements of record that have a node name that contains the string "blah"?

    var rec:XML = <record>
         <XblahX/>
         <cow/>
         <YblahY/>
    </record>;
    var r:RegExp = /blah/;
    var elems:XMLList = rec.children().(localName().search(r)>-1);
    trace(elems.toXMLString())

  • Replace n strings

    hello,
    i have a string that contain some words that i want to replace to other words.
    replace can do just one and i want in onw sql to replace n strings.
    for example:
    i have the string:
    "this is a test string and i want to replace several words"
    i want to replace the words: test with aaa,want with bbb,several with ccc.
    so after it will be:
    "this is a aaa string and i bbb to replace ccc words"
    how can i do it in one sql or what is the best way to do it ?
    thanks
    Zvika

    You can try to do this with using of MODEL clause.
    SELECT cur_val
    FROM (SELECT 1 AS dim_col, 'this is a test string and i want to replace several words' AS cur_val FROM dual)
    MODEL
    DIMENSION BY (dim_col)
    MEASURES (cur_val, 1 string_to_replace_num)
    UNIQUE DIMENSION
    RULES ITERATE (3)
    cur_val[1] = replace(cur_val[1],
    case string_to_replace_num[1] when 1 then 'test' when 2 then 'want' when 3 then 'several' end,
    case string_to_replace_num[1] when 1 then 'aaa' when 2 then 'bbb' when 3 then 'ccc' end
    string_to_replace_num[1] = string_to_replace_num[1] + 1
    In the row RULES ITERATE (3) - 3 is not a magic number. It is equal to total number of strings have to be replaced.

  • Replace a string in a character field with a amount value

    Hi,
        I have a text field in which I want to replace a string with an amount value. while am trying to replace it , it gives me some empty space.
    For example:
    amount = '1200   '
    message = 'The STIP amount is &1'
    in my code :
    replace &1 with message into message.
    the result is
    'The STIP amount is 1200   '
    I dont want the space after 1200.
    I tried for condense no-gaps also but it is not working ..
    What may be the problem?
    Can you suggest some solution for this?
    Regards,
    Vimala

    Hi,
    replace &1 with message into message.
    I guess its replace &1 with amount into message.
    Convert the amount to a character type (example move amount to amount_c ), then condense it and and then replace it using the 'REPLACE' statement.
    regards,
    Advait.

  • Replace a string with another string in a file

    I have to replace a string with another string. Say for example in a html file it got a line like,
    <a href="##"></a>
    now i want to replace this ## with the full derived path like
    "c;\\sample folder\\sample subfolder\\samplefile.html"
    can someone help me to do this?
    pls tell me from the file opening till closing the file.

    I have to replace a string with another string. Say
    for example in a html file it got a line like,
    <a href="##"></a>
    now i want to replace this ## with the full derived
    path like
    "c;\\sample folder\\samplesubfolder\\samplefile.html"
    can someone help me to do this?
    pls tell me from the file opening till closing the
    file.
    public class Buckel {
      final static String CONST = "c:\\sample folder\\samplesubfolder\\samplefile.html";
      public Buckel() {
      public static void main ( String[] argv )  throws Exception {
        int    idx = 0;
        String in  = "<a href=\"##\"></a>",   // We'll imagine this just gets here somehow. If it's on the i/p file then take the '\' out B4 and aft the '##'.
               out = "";
        idx = in.indexOf( "##" );
        if ( idx > 0 ) {
          out = in.substring( 0, idx ) + CONST + in.substring( idx+=2, in.length() );
        System.out.println( out );
    }

  • String pattern match

    hi all.
    there is a request :
    get user input string, and use it as string Pattern regular expression, to match the first string in the memory, and print it.
    a JTextField to get user input, and to create regular expression :
    //breg is user input string.
    if( !breg.endsWith("*") ) breg += "*";
    //only alow a-z, A-Z, 0-9, _ , -, . , :, , , \ , /
    String reg = breg.replaceAll("\\*",
    "[a-zA-Z0-9_ \\\\./\\\\:,\\\\-\\\\\\\\]*").
    replaceAll("\\?", "[a-zA-Z0-9_ \\\\./\\\\:,\\\\-\\\\\\\\]");
    then in a loop to check the string in an array tha match this regular expression.
    But when input \ it will not match.
    Is there any problem in my regular expression.
    ??????????

    And the base class is
    public abstract class SearchInputLabel implements KeyListener{
      JWindow dialog = null;
      Component onComponent = null;
      JPanel jPanel1 = new JPanel();
      BorderLayout borderLayout1 = new BorderLayout();
      JLabel jLabelS = new JLabel();
      JTextField jTextField1 = new JTextField();
      Border border1;
       * @param onComponent : it should be a JTable, JTree or JList has been added into
       *                      JViewport in JScrollPane
       *                      else there if it is null, it should be setted after it has been
       *                      added into JViewport in JScrollPane
      protected SearchInputLabel(Component onComponent) {
        this();
        if( onComponent != null ){
          this.onComponent = onComponent;
          onComponent.addKeyListener(this);
      protected SearchInputLabel(){
        try {
          jbInit();
          jTextField1.addKeyListener(this);
        catch(Exception e) {
          e.printStackTrace();
       * @param onComponent : if null, there will do nothing
      public void setOnComponent(Component onComponent){
        if (onComponent != null) {
          this.onComponent = onComponent;
          onComponent.addKeyListener(this);
      private void cancel(){
        dialog.setVisible(false);
        onComponent.requestFocus();
      private void initWin(){
        Window w = (Window) ( (JViewport) onComponent.getParent()).getRootPane().
            getParent();
        dialog = new JWindow(w);
    //    dialog.getContentPane().setBackground(new Color(180, 215, 165));
        dialog.getContentPane().setBackground(new Color(Color.white.getRed() - 50,
            Color.white.getGreen() - 50,
            Color.white.getBlue() - 50));
        dialog.getContentPane().add(jPanel1, BorderLayout.CENTER);
        dialog.addWindowFocusListener(new WindowAdapter(){
          public void windowLostFocus(WindowEvent we){
            cancel();
        KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        Action escapeAction = new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            cancel();
        dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape,
            "ESCAPE");
        dialog.getRootPane().getActionMap().put("ESCAPE", escapeAction);
      protected void showing(){
        if( dialog == null )
          initWin();
      private void jbInit() throws Exception {
        border1 = BorderFactory.createEmptyBorder(5,10,5,10);
        Border border2 = BorderFactory.createCompoundBorder(
            new LineBorder(Color.BLUE), border1);
        border2 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(SystemColor.inactiveCaption,2),BorderFactory.createEmptyBorder(5,10,5,10));
    //    dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    //    dialog.setUndecorated(true);
        jPanel1.setLayout(borderLayout1);
        jLabelS.setRequestFocusEnabled(true);
        jLabelS.setText(DBManager.getString("Search_for_label") + " : ");
        jTextField1.setOpaque(false);
        jTextField1.setBackground(Color.GRAY);
        jPanel1.setOpaque(false);
        jPanel1.setBorder(border2);
        jPanel1.add(jLabelS,  BorderLayout.WEST);
        jPanel1.add(jTextField1,  BorderLayout.CENTER);
        jTextField1.setBorder(null);
    //    jTextField1.setFont(new Font("Dialog", Font.PLAIN, 14));
      protected int getStringWidth(String str, Font f){
        Rectangle2D rec = f.getStringBounds(str,
                                            ( (Graphics2D) dialog.getGraphics()).getFontRenderContext());
        return (int) rec.getWidth();
    }But if there is "\" in table object's value, it can not do well.
    So some one can help me to make it response for "\" character
    Thanks

Maybe you are looking for