写一个去除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几乎为你把所有的繁重工作都做了,比如解码.编码. ...
随机推荐
- Android 自己定义ViewGroup 实战篇 -> 实现FlowLayout
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38352503 .本文出自[张鸿洋的博客] 1.概述 上一篇已经基本给大家介绍了怎 ...
- WCF REST 基础教程
概述 Representational State Transfer(REST)是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格. 因此REST是设计风格而不是标准,R ...
- DSO Framer _ WinForm 使用
根据自己对dsoframer控件的学习,想把dsoframer控件进行简单的包装为C#的usercontrol,大体需要作如下:(创建windows的usercontrol的步骤就不再说了...)我们 ...
- angular2的编译模式之AOT和JIT
原文 https://www.jianshu.com/p/c959d90e91ce 大纲 1.angular应用为什么需要编译 2.angular的编译模式类型 3.JIT(Just-In-Time) ...
- crx 【 集合 】
Vimium dbepggeogbaibhgnhhndojpepiihcmeb-1.64-Crx4Chrome.com.crx https://www.crx4chrome.com/down/731/ ...
- 驱动程序调试方法之printk——printk的原理与直接使用
1.基本原理 (1)在UBOOT里设置console=ttySAC0或者console=tty1 这里是设置控制终端,tySAC0 表示串口, tty1 表示lcd(2)内核用printk打印 内核就 ...
- oracle 列授权相关测试
create tablespace liangtbs datafile '/home/oradata/lgjdb/liangtbs01.dbf' size 50m autoextend on;crea ...
- Nginx+uswgi+Django部署
详情参考: http://blog.csdn.net/a_little_snail/article/details/78045636
- c3p0 xml配置文件模版
<c3p0-config> <default-config> <property name="driverClass">com.mysql.jd ...
- Cisco IOS images
Cisco IOS images for Dynamips - GNS3http://docs.gns3.com/1-kBrTplBltp9P3P-AigoMzlDO-ISyL1h3bYpOl5Q8m ...