leonard chan leonard chan - 18 days ago 7
C# Question

Replace Dictionary Value with NewLine

I'm currently attempting to add custom tool tips as an extension to my Visual Studio.

However, upon hovering above the keyword, (because I have very long descriptions, I tried using \r\n but it clearly does not work and will appear as \r\n in the tool tip so I used)

//var reader = new StreamReader(File.OpenRead(@"C:\xx\QuickInfo.csv"));
/*while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
//add in values in position 0 and 1
m_dictionary.Add(values[0], values[1].Replace("<br>", Environment.NewLine));
}*/


space

internal class VCLToolTipSource: IQuickInfoSource
{
private VCLToolTipSourceProvider m_provider;
private ITextBuffer m_subjectBuffer;
private Dictionary<string, string> m_dictionary;
public VCLToolTipSource(VCLToolTipSourceProvider provider, ITextBuffer subjectBuffer)
{
m_provider = provider;
m_subjectBuffer = subjectBuffer;

m_dictionary = new Dictionary<string, string>();

//CSV for Quick Info
//var reader = new StreamReader(File.OpenRead(@"C:\xx\QuickInfo.csv"));
//For going through CSV positions 0,1//
/*while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
//add in values in position 0 and 1
m_dictionary.Add(values[0], values[1].Replace("<br>", Environment.NewLine));
}*/

//List of all tool tips//


m_dictionary.Add("keyword", "value");
m_dictionary.Add("adapt", " - Process given file <br>Syntax: #adapt[(-samelevel|-continue|-samelevel-continue|-copy)][:] path [output-folder] [output-file]( vcl-command )*[#endadapt]<br>Variations:<br><br> -samelevel : The scope of the adapted file will be raised to the current level which makes it possible to override variables<br> -continue : If the adaptable file is not found continue processing. (warning message instead of stop processing with error)<br>Note: #adapt-continue will open the file and process it. Unlike #adapt-copy.<br> -copy : Instead of processing the file");


which is to replace all "<br>" with the Environment.Newline to shorten it.

However, now that I do not want to use a CSV file to import data, how to I read the data from the dictionary and replace <br> with a Newline??

Thank you

Answer

Perhaps this is more along the lines of what you want to do?

m_dictionary = m_dictionary.ToDictionary(
                                k => k.Key, 
                                v => v.Value.Replace("<br>", Environment.NewLine));

This will go through the entire dictionary and replace any "<br>" values with Environment.NewLine.

Comments