Skip to content

Replace String

Chetan koralli

Asked Jan 20, 2012, 4:54 AM ESTSolved
Share
LinkedInX
Hi,

can any one help me,

my string is as folllows


string pdfPath = @" \\fs09\data22\IMAGEPDF\Production\69273\IMAGEPDF\001";

i want last "IMAGEPDF" should be Replaced with "PDF".


Thanks&Regards,
Chetan.k

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • ✓ Accepted answer0
    Code
    Hope this helps you.
    
    string pdfPath = @" \\fs09\data22\IMAGEPDF\Production\69273\IMAGEPDF\001";
    int idx = pdfPath.LastIndexOf("IMAGEPDF");
    pdfPath = pdfPath.Remove(idx, 5);
    0
  • 0
    Hi,


    string pdfPath = @" \\fs09\data22\IMAGEPDF\Production\69273\IMAGEPDF\001";

     pdfPath = pdfPath.Replace("IMAGEPDF", "PDF");

    i think it helps

    jitendra
    0
  • 0
    Hi,

    Here is the full code. This will replace "IMAGEPDF" by "PDF" (or anything instead of "PDF")

    using System;

    class StringHandle
    {
        static void Main()
        {
            string pdfPath = @" \\fs09\data22\IMAGEPDF\Production\69273\IMAGEPDF\001";
            string repStr = "IMAGEPDF";
            int idx = pdfPath.LastIndexOf(repStr);
            int length = repStr.Length;
            pdfPath = pdfPath.Remove(idx, length);
            pdfPath = pdfPath.Insert(idx, "PDF");
            Console.WriteLine(pdfPath);
           
        }
    }


    First this removes the last "IMAGEPDF" and then it is replaced by "PDF". You can test it by any string to replace "IMAGEPDF".
    0
  • 0
    Thanks Murli Your reply helped me
    0