C# 用换行符替换字典值

C# 用换行符替换字典值,c#,visual-studio,dictionary,intellisense,C#,Visual Studio,Dictionary,Intellisense,我目前正试图将自定义工具提示添加到我的Visual Studio中作为扩展 但是,在将鼠标悬停在关键字上方时,(因为我有很长的描述,所以我尝试使用\r\n,但它显然不起作用,并且将在我使用的工具提示中显示为\r\n) //var reader=new StreamReader(File.OpenRead(@“C:\xx\QuickInfo.csv”); /*而(!reader.EndOfStream) { var line=reader.ReadLine(); var值=行分割(','); //

我目前正试图将自定义工具提示添加到我的Visual Studio中作为扩展

但是,在将鼠标悬停在关键字上方时,(因为我有很长的描述,所以我尝试使用\r\n,但它显然不起作用,并且将在我使用的工具提示中显示为\r\n)

//var reader=new StreamReader(File.OpenRead(@“C:\xx\QuickInfo.csv”);
/*而(!reader.EndOfStream)
{
var line=reader.ReadLine();
var值=行分割(',');
//在位置0和1中添加值
m_dictionary.Add(值[0],值[1]。Replace(“
”,Environment.NewLine)); }*/
空间

内部类VCLToolTipSource:IQuickInfoSource
{
私人VCLTOLTIPSourceProvider m_提供商;
私有ITextBuffer m_subjectBuffer;
私家词典;
公共VCLTOLTIPSource(VCLTOLTIPSourceProvider提供程序,ITextBuffer subjectBuffer)
{
m_provider=提供者;
m_subjectBuffer=subjectBuffer;
m_dictionary=新字典();
//CSV用于快速信息
//var reader=newstreamreader(File.OpenRead(@“C:\xx\QuickInfo.csv”);
//用于通过CSV位置0,1//
/*而(!reader.EndOfStream)
{
var line=reader.ReadLine();
var值=行分割(',');
//在位置0和1中添加值
m_dictionary.Add(值[0],值[1]。Replace(“
”,Environment.NewLine)); }*/ //所有工具提示的列表// 添加(“关键字”、“值”); m_dictionary.Add(“adapt”,“-处理给定文件
语法:#adapt[(-samelevel-continue-samelevel-continue-copy)][:]路径[输出文件夹][输出文件](vcl命令)*[#endadapt]
变体:

-samelevel:修改文件的范围将提升到当前级别,从而可以覆盖变量
-继续:如果未找到修改文件,则继续处理。(警告消息,而不是错误停止处理)
注意:#自适应继续将打开文件并对其进行处理。与#自适应复制不同。
-copy:而不是处理文件”);
将所有“”替换为环境。换行以缩短它

但是,现在我不想使用CSV文件导入数据,如何从字典中读取数据并替换为换行


谢谢

您是否尝试添加字符串。请在字符串末尾替换(“

”,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));
m\u字典
.Add(“adapt”,
“-处理给定文件
语法:#adapt[(-samelevel |-continue-samelevel continue |-copy)][:]路径[输出文件夹][输出文件](vcl命令)*[#endadapt]
变体:

-samelevel:修改文件的范围将提升到当前级别,从而可以覆盖变量
-继续:如果未找到修改文件,则继续处理。(警告消息,而不是错误停止处理)
注意:#自适应继续将打开文件并对其进行处理。与#自适应复制不同。
-复制:而不是处理文件” .Replace(“
”,Environment.NewLine));
将“

”替换为
环境。换行符
\n

代码:

string str=“-Process给定文件
语法:#adapt[(-samelevel-continue-samelevel continue-copy)][:]路径[输出文件夹][输出文件](vcl命令)*[#endadapt]
变体:

-samelevel:修改文件的范围将提升到当前级别,从而可以覆盖变量
-继续:如果未找到修改文件,则继续处理。(警告消息,而不是错误停止处理)
注意:#自适应继续将打开文件并对其进行处理。与#自适应复制不同。
-复制:而不是处理文件”; str=str.Replace(“
”,Environment.NewLine);

str=str.Replace(“
”,“\n”);
输出: -处理给定文件
语法:#adapt[(-samelevel |-continue |-samelevel continue |-copy)][:]路径[输出文件夹]输出文件*[#endadapt] 变化:

-samelevel:调整后的文件的范围将提升到当前级别,从而可以覆盖变量 -继续:如果找不到适配文件,则继续处理。(警告消息,而不是错误停止处理) 注意:#adapt continue将打开文件并对其进行处理。与#adapt 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;  
}
public string ReplaceBRwithNewline(string txtVal)
{  
字符串newText=“”;
//创建正则表达式
System.Text.RegularExpressions.Regex Regex=
新的System.Text.RegularExpressions.Regex(@“(

|
)”; //将新行替换为标签
newText=regex.Replace(txtVal,“\r\n”); //结果 返回新文本; }

我将这里替换为
\r\n
,因为在某些浏览器上,它与
\n
一起工作,在某些浏览器上,它与
\r\n
一起工作,也许这更符合您的要求

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

这将遍历整个词典并替换任何

使用
环境值。换行符

您希望用换行符替换整个值?还是只使用
标记?每当标记
时,我都需要一个新行。但我拥有的是一个字典,需要添加一组字典项。m_dictionary.add(“关键字,“值”)您可以通过foreach循环对字典中的所有值执行此操作,但您知道如何使用m_字典。添加(值[0],值[1]。替换(“
”,Environment.NewLine));而不是“Environment.Newli”
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");
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;  
}
m_dictionary = m_dictionary.ToDictionary(
                                k => k.Key, 
                                v => v.Value.Replace("<br>", Environment.NewLine));