写一个去除AI2XAML注释及多余数字位数的WPF窗体程序
原文:写一个去除AI2XAML注释及多余数字位数的WPF窗体程序
使用正则表达式去除多余注释及冗余数字位,关键代码:
string pattern = @"/b(/d+)/.(/d{1})/d+([/,/s]?)/b";
string temp = Regex.Replace(oldContent, pattern, @"$1.$2$3");
temp = Regex.Replace(temp, @"<!--.*-->", "");
temp = Regex.Replace(temp, @"[/s| ]*/r","");
运行效果截图:
// ReplaceWindow.xaml
<Window x:Class="BrawDraw.Com.AIXamlConverter.ReplaceWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="600" Width="800">
<Grid>
<Label Height="28" Margin="45,17,219,0" Name="label1" VerticalAlignment="Top" Foreground="Red">将XAML内容复制到下面文本框内,然后点替换,在“结果”文本框中得到新内容。</Label>
<Button Height="23" HorizontalAlignment="Right" Margin="0,17,119,0" Name="btnReplace" VerticalAlignment="Top" Width="75" Click="btnReplace_Click">替换</Button>
<TextBox Margin="124,45,26,0" Name="txtBoxOldContent" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Height="151" VerticalAlignment="Top" />
<TextBox Margin="124,200,26,201" Name="txtBoxResultContent" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" />
<Label Height="28" HorizontalAlignment="Left" Margin="45,45,0,0" Name="label2" VerticalAlignment="Top" Width="91">替换前内容:</Label>
<Label Height="28" HorizontalAlignment="Left" Margin="45,200,0,0" Name="label3" VerticalAlignment="Top" Width="91">结果:</Label>
<StackPanel Margin="123,0,27,12" Height="180" VerticalAlignment="Bottom">
<Border BorderBrush="Black" BorderThickness="1" Height="180" Name="borderResult">
<StackPanel Name="spResult" />
</Border>
</StackPanel>
<Label Height="28" HorizontalAlignment="Left" Margin="45,0,0,164" Name="label4" VerticalAlignment="Bottom" Width="91">效果预览:</Label>
</Grid>
</Window>
// ReplaceWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Text.RegularExpressions;
namespace BrawDraw.Com.AIXamlConverter
{
/// <summary>
/// Interaction logic for ReplaceWindow.xaml
/// </summary>
public partial class ReplaceWindow : Window
{
public ReplaceWindow()
{
InitializeComponent();
}
private void btnReplace_Click(object sender, RoutedEventArgs e)
{
string oldContent = txtBoxOldContent.Text;
//string pattern = @"(/d+)/.(/d)/d{5,}([/,/s]?)";
string pattern = @"/b(/d+)/.(/d{1})/d+([/,/s]?)/b";
string temp = Regex.Replace(oldContent, pattern, @"$1.$2$3");
temp = Regex.Replace(temp, @"<!--.*-->", "");
temp = Regex.Replace(temp, @"[/s| ]*/r","");
txtBoxResultContent.Text = temp;
try
{
//下面的代码用于预览效果显示:
System.IO.StringReader stringReader = new System.IO.StringReader(temp);
System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader);
UIElement uie = (UIElement)System.Windows.Markup.XamlReader.Load(xmlReader);
spResult.Children.Add(uie);
borderResult.BorderBrush = Brushes.Transparent;
}
catch (Exception exc)
{
MessageBox.Show(string.Format("出错了,错误是:/r/n{0}", exc.Message));
}
}
}
}
写一个去除AI2XAML注释及多余数字位数的WPF窗体程序的更多相关文章
- 用java写一个两个任意长度字符串数字和的算法
package com.cn.test.string; public class StringTest { public static void main(String[] args) { Strin ...
- 根据python上下文管理,写一个在读文件内容前后自动打开关闭文件的程序
利用上下文管理实现读f文件前后自动打开关闭文件#在本目录创建f文件,内容写monkey代码如下 import contextlib #导入模块1 @contextlib.contextmanager# ...
- 用python写一个非常简单的QQ轰炸机
闲的没事,就想写一个QQ轰炸机,按照我最初的想法,这程序要根据我输入的QQ号进行轰炸,网上搜了一下,发现网上的案列略复杂,就想着自己写一个算了.. 思路:所谓轰炸机,就是给某个人发很多信息,一直刷屏, ...
- 自动化测试(三)如何用python写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的邮箱不能重复。
写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的邮箱不能重复.邮箱前面的长度是6-12之间,产生的邮箱必须包含大写字母.小写字母.数字和特殊字符 和上一期一样 代码中间有段比较混沌 有 ...
- 写一个方法完成如下功能,判断从文本框textbox1输入的一个字符,如果是数字则求该数字的阶乘,如果是小写字条,则转换为大写,大写字符不变,结果在文本框textbox2中显示
窗体设计: 代码: using System; using System.Collections.Generic; using System.ComponentModel; using System. ...
- 大一C语言学习笔记(11)---编程篇--写一个程序,可以获取从键盘上输入的的三个数,并能够判断是否可以以这三个数字作为边长来构成一个三角形,如果可以的话,输出此三角形的周长及面积,要求 0 bug;
考核内容: 写一个程序,可以获取从键盘上输入的的三个数,并能够判断是否可以以这三个数字作为边长来构成一个三角形,如果可以的话,输出此三角形的周长及面积: 答案: #include<stdio.h ...
- 仿照jQuery写一个关于选择器的框架(带了注释,请多多指教~)
var select = (function () { //这是一个异常与捕获的代码,它表示的意思是:如果push方法出现了错误那么就需要重写push方法 try { //这边是自己模拟一个场景,来使 ...
- 比最差的API(ETW)更差的API(LTTng)是如何炼成的, 谈如何写一个好的接口
最近这几天在帮柠檬看她的APM系统要如何收集.Net运行时的各种事件, 这些事件包括线程开始, JIT执行, GC触发等等. .Net在windows上(NetFramework, CoreCLR)通 ...
- (转)如何基于FFMPEG和SDL写一个少于1000行代码的视频播放器
原文地址:http://www.dranger.com/ffmpeg/ FFMPEG是一个很好的库,可以用来创建视频应用或者生成特定的工具.FFMPEG几乎为你把所有的繁重工作都做了,比如解码.编码. ...
随机推荐
- vs2008,2010,2012安装包下载
近期在csdn学院当老师啦.把自己以学到的东西总结一下,录个视频给大家,也当发一下福利.这些以后都是自己无形的財产.哈哈. 安装与下载编程工具 Vs2008下载地址:http://pan.baidu. ...
- 五一巨献,问答有礼,105QB送给IT互联网界的劳动人民
活动主题:五一巨献,问答有礼,105QB送给IT互联网界的劳动人民活动时间:4月30日晚上10点~5月2日晚上10点活动期数:第1期,20150401 奖品:105QB获奖人数:20人1~5:每人10 ...
- 结构体(struct)与类(class)
在 C++ 的范畴里,除了 struct 结构体不支持访问权限修饰符(private.protected.public)外,已不再区分二者的其他方面语法上的差异. 因此,在 C++ 编程中,如果一个类 ...
- 【机器学习实战】第3章 决策树(Decision Tree)
第3章 决策树 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/ ...
- [React Router v4] Redirect to Another Page
Overriding a browser's current location without breaking the back button or causing an infinite redi ...
- 网络异常与SQL Server事务
SQL Server事务遭遇网络异常时的处理机制浅析 SQL Server数据库中,如果应用程序正在执行一个事务的时候突然遭遇了网络异常,例如网络掉包,网络中断等,那么这个事务会怎么样? SQL Se ...
- 【codeforces 755B】PolandBall and Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【poj 1704】Georgia and Bob
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9776 Accepted: 3222 Description Georgia a ...
- Identifying a distributed denial of service (DDOS) attack within a network and defending against such an attack
The invention provides methods, apparatus and systems for detecting distributed denial of service (D ...
- 数组类型转换失败:NSMutableArray和NSArray的相互转换
1.数组类型转换无效(错误) @property(strong, nonatomic) NSMutableArray *temp_Array; _temp_Array=(NSMutableArray ...