[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Append "/" to a string

Posted on 2008-09-30
13
Medium Priority
?
1,082 Views
Last Modified: 2013-12-17
How do i append the character \ to a string
rtf = rtf + @"\"; this is not working nor is this
rtf = rtf + "\\"; neither this
rtf = rtf + "\"; //this doesnt work escape
0
Comment
Question by:Dawie de Villiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22612041
actually, the 2 first examples should work...
can you clarify "not working", please?
0
 
LVL 14

Expert Comment

by:Jai S
ID: 22612049
you use string.Format

rtf = string.Format(@"{0}\", rtf);
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22612063
i tried this and it worked correctly

string rtf = string.Empty;
rtf += @"\";
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22612079
this will work:

rtf = rtf + @"\\";
0
 
LVL 3

Expert Comment

by:trunghieubkit
ID: 22612153
Use this code snippet, I'm sure it's OK.
You may not initialize empty value for rtf variable?

        private void Func()
        {
            String rtf = "";
            rtf = rtf + @"\";
            rtf = rtf + "\\";
        }

Open in new window

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22612177
The author question is: how to APPEND a backslash to a RTF text
The backslash is a very special character in RTF, so you will need to escape it with a double backslash.
If you start with an empty rtf, then a single backslash can be shown, but I guess that's not what the author is asking for.
0
 

Author Comment

by:Dawie de Villiers
ID: 22612293
rtf = "Testing Image Embading<br />\r\n<img alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\" /><br />\r\nEmage Embabeded here\r\n"
Regex exp = new Regex(@"img (alt=\.)?([^\.]+)\.png", RegexOptions.IgnoreCase);
                string InputText = rtf;
                MatchCollection MatchList = exp.Matches(InputText);
                Match FirstMatch = MatchList[0];
                for (int i = 0; i < MatchList.Count; i++)
                {
                    string str = @"\";                
                    string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\"", rep);
                    string strToReplace; //= MatchList[i].ToString(); //;+ str;
                    //strToReplace = strToReplace.Substring(0, strToReplace.Length);
                    strToReplace = string.Format(@"{0}\", MatchList[i].ToString());
                    rtf = rtf.Replace(strToReplace, rep);
i hard corded rtf1 and it worked fine so what i want is for strToReplace to be equal to this string Web%20Cleint/Home%20Page/Images/Stop.png\"
and im trying to achieve that by using this string  string strToReplace; //= MatchList[i].ToString() + str;
it appends 2 \\ and doesnt match the other string
I hope this will help.
0
 

Author Comment

by:Dawie de Villiers
ID: 22612323
Guys this is what im doing for now
 string str = "\"";  
strToReplace = strToReplace + str and i will have to remove the additonal " after this string.

Is this the best way to do this?????
I dont know if i have to close the question or not
0
 

Author Comment

by:Dawie de Villiers
ID: 22612326
Thank you very much
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22612333
> string str = "\"";  
is to append a double quote to the string...
which is not what you "asked" for?

I guess you don't want to tell us the "big picture"?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22612349
your last comments are confusing and unrelated with your original question...
0
 

Author Comment

by:Dawie de Villiers
ID: 22612943
string str = "\"";                
 string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\"", rep);
string strToReplace = MatchList[i].ToString()+ str;
rtf = rtf.Replace(strToReplace, rep);
I asked for assistance on how to add a \ on my string, and as a  highlited earlier on if  
MatchList[i].ToString() = "alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png ", my replace function wasnt working so i needed to add a single \ to the matchlist and so during run time @"\" will add two \\.
May you please append   string str = "\"";      to one string and do a replace at runtime and observe the results and do the same with str = @"\"; it wont work coz its got 2 \\.

I sorry for the confusion this might have caused.
 
0
 
LVL 3

Accepted Solution

by:
trunghieubkit earned 2000 total points
ID: 22620878
Using the Snippet below,

Importance:
I replaced the row
            string str = "\"";
by
            string str = "\\\"";

It'll be printed on Output screen (Ctrl+Alt+O) exactly what you want

img alt="" src="/Web%20Cleint/Home%20Page/Images/Stop.png\"
public void Replace()
{
    String rtf = "Testing Image Embading<br />\r\n<img alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\" /><br />\r\nEmage Embabeded here\r\n";
 
    Regex exp = new Regex(@"img (alt=\.)?([^\.]+)\.png", RegexOptions.IgnoreCase);
        
    string InputText = rtf;
    MatchCollection MatchList = exp.Matches(InputText);
 
    for (int i = 0; i < MatchList.Count; i++)
    {
        string str = "\\\"";                
        string strToReplace = MatchList[i].ToString() + str;
        Console.WriteLine(strToReplace);
    }
}

Open in new window

0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question