贴吧发东西,因为好多敏感不能发。在文字加上空格就可以。
如我需要发下面的文字
敏感的,百度不发
在每个字后面添加了空格,于是转换之后的文字请看下面
敏 感 的 , 百 度 不 发
如果需要每次都在文字后面添加空格,这个输入就不太好了,下面我就使用 WPF 做一个工具,用于在输入的字符串中,自动在每个文字后面添加空格
下面是核心的代码
StringBuilder temp=new StringBuilder();
int i;
if (要增加 == "")
{
要增加 = " ";
}
for (i = 0; i < str.Length; i++)
{
temp.Append(str[i]);
temp.Append(要增加);
}
str = temp.ToString();
//要增加是字符串
public string 要增加
{
set
{
//_要增加 = value;
_要增加.Clear();
_要增加.Append(value);
OnPropertyChanged("要增加");
}
get
{
return _要增加.ToString();
}
}
/// <summary>
/// 要加空格文
/// </summary>
public string str
{
set
{
//_str = value;
_str.Clear();
_str.Append(value);
OnPropertyChanged("str");
}
get
{
return _str.ToString();
}
}
如果每次需要打开软件,从剪贴板复制一下,还是不太好,于是使用下面的代码自动将文字设置到剪贴板
在文字增加空格();
Clipboard.SetText(str);
还需要通过监听剪贴板的方式,每个 0.1 秒读取剪贴板,如果发现有文字了,就尝试在文字后面添加空格
private DispatcherTimer game_Main_timer;
game_Main_timer = new DispatcherTimer();
game_Main_timer.Interval = TimeSpan.FromSeconds(0.1);
//到达时间后执行GameMianTimer_Tick事件
game_Main_timer.Tick += GameMainTimer_Tick;
game_Main_timer.Start();
private void GameMainTimer_Tick(object sender,EventArgs e)
{
viewModel.g_viewModel().改剪贴();
}
这里修改剪贴板不能每次都修改,需要判断剪贴板的内容,如果剪贴板的内容已经修改了,就不需要再修改
private StringBuilder 有改=new StringBuilder();
public void 改剪贴()
{
//如果有改,false
str = Clipboard.GetText();
if(str.Equals(有改.ToString())==false)
{
在文字增加空格();
有改.Clear();
有改.Append(str);
Clipboard.SetText(str);
}
}
这里的界面很简单,请看下面
<Window x:Class="_2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="文字空格" Height="350" Width="525">
<Grid>
<TextBox HorizontalAlignment="Left" Height="204" Margin="10,10,0,0" TextWrapping="Wrap" Text="{Binding Path=str}" VerticalAlignment="Top" Width="498" AcceptsReturn="True"/>
<StackPanel Orientation="Vertical" Margin="10,10,10,10" VerticalAlignment="Bottom">
<StackPanel Orientation="Horizontal" Margin="10,10,10,10" VerticalAlignment="Bottom">
<TextBlock Text="增加" Margin="10,10,10,10"/>
<TextBox Text="{Binding Path=要增加}" HorizontalAlignment="Left" Width="200" Margin="10,10,10,10"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="10,10,10,10" >
<Button Content="确定" HorizontalAlignment="Right" Margin="10,10,10,10" VerticalAlignment="Top" Click="文字增加"/>
<Button x:Name="xt" Content="停" HorizontalAlignment="Right" Margin="10,10,10,10" Click="停"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接:http://blog.csdn.net/lindexi_gd ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系。