本文整理汇总了C#中TextEditorData.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.Replace方法的具体用法?C# TextEditorData.Replace怎么用?C# TextEditorData.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditorData
的用法示例。
在下文中一共展示了TextEditorData.Replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToggleCase
public static void ToggleCase (TextEditorData data)
{
if (data.IsSomethingSelected) {
if (!data.CanEditSelection)
return;
StringBuilder sb = new StringBuilder (data.SelectedText);
for (int i = 0; i < sb.Length; i++) {
char ch = sb[i];
if (Char.IsLower (ch))
sb[i] = Char.ToUpper (ch);
else if (Char.IsUpper (ch))
sb[i] = Char.ToLower (ch);
}
data.Replace (data.SelectionRange.Offset, data.SelectionRange.Length, sb.ToString ());
}
else if (data.CanEdit (data.Caret.Line)) {
char ch = data.Document.GetCharAt (data.Caret.Offset);
if (Char.IsLower (ch))
ch = Char.ToUpper (ch);
else if (Char.IsUpper (ch))
ch = Char.ToLower (ch);
int length = data.Replace (data.Caret.Offset, 1, new string (ch, 1));
LineSegment seg = data.Document.GetLine (data.Caret.Line);
if (data.Caret.Column < seg.EditableLength)
data.Caret.Offset += length;
}
}
示例2: Join
public static void Join (TextEditorData data)
{
int startLine, endLine, startOffset, length, lastSpaceOffset;
if (data.IsSomethingSelected) {
startLine = data.Document.OffsetToLineNumber (data.SelectionRange.Offset);
endLine = data.Document.OffsetToLineNumber (data.SelectionRange.EndOffset - 1);
} else {
startLine = endLine = data.Caret.Line;
}
//single-line joins
if (endLine == startLine)
endLine++;
if (endLine > data.Document.LineCount)
return;
LineSegment seg = data.Document.GetLine (startLine);
startOffset = seg.Offset;
StringBuilder sb = new StringBuilder (data.Document.GetTextAt (seg).TrimEnd ());
lastSpaceOffset = startOffset + sb.Length;
for (int i = startLine + 1; i <= endLine; i++) {
seg = data.Document.GetLine (i);
lastSpaceOffset = startOffset + sb.Length;
sb.Append (" ");
sb.Append (data.Document.GetTextAt (seg).Trim ());
}
length = (seg.Offset - startOffset) + seg.EditableLength;
// TODO: handle conversion issues ?
data.Replace (startOffset, length, sb.ToString ());
data.Caret.Offset = lastSpaceOffset;
}