我目前正在尝试添加自定义工具提示作为我的Visual Studio的扩展程序。
然而,当悬停在关键字上方时,(因为我有很长的描述,我尝试使用\ r \ n但它显然不起作用,并且在工具提示中显示为\ r \ n所以我使用了)
//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));
}*/
空间
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");
替换所有&#34;&lt; br &gt;&#34;与Environment.Newline缩短它。
但是,现在我不想使用CSV文件导入数据,如何从字典中读取数据并替换&lt; br &gt;用换行符?
谢谢
答案 0 :(得分:1)
也许这更符合你想做的事情?
m_dictionary = m_dictionary.ToDictionary(
k => k.Key,
v => v.Value.Replace("<br>", Environment.NewLine));
这将遍历整个字典,并将所有"<br>"
值替换为Environment.NewLine
。
答案 1 :(得分:0)
您是否尝试在字符串末尾添加yourstring.Replace(“<br>
”,Environment.NewLine)。
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"
.Replace("<br>", Environment.NewLine));
答案 2 :(得分:0)
将“<br>"
替换为Environment.NewLine
或\n
。
代码:
string str = " - 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";
str = str.Replace("<br>", Environment.NewLine);
或
str = str.Replace("<br>", "\n");
输出:
- 处理给定文件
语法:#adapt [( - samelevel | -continue | -samelevel-continue | -copy)] [:] path [output-folder] output-file * [#endadapt]
变化:
-samelevel:已调整文件的范围将提升到当前级别,从而可以覆盖变量 -continue:如果找不到自适应文件,则继续处理。 (警告消息而不是因错误而停止处理) 注意:#adcust-continue将打开文件并进行处理。与#adcust-copy不同。 -copy:而不是处理文件
虽然我的上述答案在理想情况下运行良好,但你必须涵盖所有情况。
public string ReplaceBRwithNewline(string txtVal)
{
string newText = "";
// Create Regex
System.Text.RegularExpressions.Regex regex =
new System.Text.RegularExpressions.Regex(@"(<br />|<br/>|</ br>|</br>)");
// Replace new line with <br/> tag
newText = regex.Replace(txtVal, "\r\n");
// Result
return newText;
}
我在这里用\r\n
替换,因为在某些浏览器上它与\n
一起使用,而在某些浏览器上它与\r\n
一起使用。