2016-11-14 9 views
-2

現在、Visual Studioの拡張機能としてカスタムツールヒントを追加しようとしています。辞書値をNewLineに置き換えます。

しかし、(私は非常に長い説明があるので、\ 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)); 
    }*/ 

それを短くするEnvironment.Newlineで、すべての "< BR>" を交換することでスペース

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"); 

しかし、今私は、データをインポートするCSVファイルを使用しないことを、私は辞書からデータを読み込み、改行で< BR>を置き換える方法?

は、文字列の末尾にyourstring.Replace( "<br>"、Environment.NewLine)を追加しようとしたんでした

+0

あなたは全体の値を新しい行に置き換えたいですか?または
タグのみですか? –

+0


にタグが付いているときはいつでも、新しい行が必要です。 –

答えて

1

これはおそらくあなたがやりたいことの行に沿っていますか?

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

これは辞書全体を通過し、Environment.NewLineで任意の"<br>"値を置き換えます。

+0

こんにちは、はい、これは本当に近いですが、それでも
と表示されます): –

+0

@leonardchan私は答えを投稿する前にこのコードをテストしましたが、正常に動作することを確認しています。 – Abion47

+0

こんにちは@ Abion47大丈夫、私の悪い、何かがビジュアルスタジオを再起動するとうまく座っていない。あなたの方法を使用して、最も簡単に動作します。 –

0

ありがとうございます。

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)); 
0

Environment.NewLineまたは\n<br>"を交換し

コード:

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)] [:]パス[出力先]出力ファイル* [#endadapt] バリエーション:

-samelevel:スコープ適応ファイルの現在のレベルに上げられ、変数をオーバーライドできるようになります。 -continue:適応可能ファイルが見つからない場合、処理を続行します。 (エラーで処理を停止する代わりに警告メッセージ) 注:#adapt-continueはファイルを開き、処理します。 #adapt-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; 
} 

一部のブラウザでは、それは\nで動作するので、私は、\r\nとここに置き換えることだし、いくつかにそれが\r\nで動作します。

+0

しかし、私が持っているものは辞書です、それは追加する必要がある辞書項目の束です。 m_dictionary.add( "キーワード" "値") –

+0

辞書 –

+0

のすべての値に対してforeachループを使用できますが、m_dictionary.Add(values [0]、values [1] .Replace() "
"、Environment.NewLine));代わりに、 "Environment.Newline"私はforeachしようとしましたが、置き換えることができませんでしたか? –

関連する問題