原文:写一个去除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窗体程序的更多相关文章

  1. 用java写一个两个任意长度字符串数字和的算法

    package com.cn.test.string; public class StringTest { public static void main(String[] args) { Strin ...

  2. 根据python上下文管理,写一个在读文件内容前后自动打开关闭文件的程序

    利用上下文管理实现读f文件前后自动打开关闭文件#在本目录创建f文件,内容写monkey代码如下 import contextlib #导入模块1 @contextlib.contextmanager# ...

  3. 用python写一个非常简单的QQ轰炸机

    闲的没事,就想写一个QQ轰炸机,按照我最初的想法,这程序要根据我输入的QQ号进行轰炸,网上搜了一下,发现网上的案列略复杂,就想着自己写一个算了.. 思路:所谓轰炸机,就是给某个人发很多信息,一直刷屏, ...

  4. 自动化测试(三)如何用python写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的邮箱不能重复。

    写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的邮箱不能重复.邮箱前面的长度是6-12之间,产生的邮箱必须包含大写字母.小写字母.数字和特殊字符 和上一期一样 代码中间有段比较混沌 有 ...

  5. 写一个方法完成如下功能,判断从文本框textbox1输入的一个字符,如果是数字则求该数字的阶乘,如果是小写字条,则转换为大写,大写字符不变,结果在文本框textbox2中显示

    窗体设计: 代码: using System; using System.Collections.Generic; using System.ComponentModel; using System. ...

  6. 大一C语言学习笔记(11)---编程篇--写一个程序,可以获取从键盘上输入的的三个数,并能够判断是否可以以这三个数字作为边长来构成一个三角形,如果可以的话,输出此三角形的周长及面积,要求 0 bug;

    考核内容: 写一个程序,可以获取从键盘上输入的的三个数,并能够判断是否可以以这三个数字作为边长来构成一个三角形,如果可以的话,输出此三角形的周长及面积: 答案: #include<stdio.h ...

  7. 仿照jQuery写一个关于选择器的框架(带了注释,请多多指教~)

    var select = (function () { //这是一个异常与捕获的代码,它表示的意思是:如果push方法出现了错误那么就需要重写push方法 try { //这边是自己模拟一个场景,来使 ...

  8. 比最差的API(ETW)更差的API(LTTng)是如何炼成的, 谈如何写一个好的接口

    最近这几天在帮柠檬看她的APM系统要如何收集.Net运行时的各种事件, 这些事件包括线程开始, JIT执行, GC触发等等. .Net在windows上(NetFramework, CoreCLR)通 ...

  9. (转)如何基于FFMPEG和SDL写一个少于1000行代码的视频播放器

    原文地址:http://www.dranger.com/ffmpeg/ FFMPEG是一个很好的库,可以用来创建视频应用或者生成特定的工具.FFMPEG几乎为你把所有的繁重工作都做了,比如解码.编码. ...

随机推荐

  1. [Nuxt] Setup a "Hello World" Server-Rendered Vue.js Application with the Vue-CLI and Nuxt

    Install: npm install -g vue-cli Init project: vue init nuxt/starter . Run: npm run dev Create a inde ...

  2. Apache多虚拟主机多版本PHP(5.3+5.6+N)共存运行配置全过程

    摘要: 为需要实现在同一台Linux服务器上面,同时运行多个不同版本的PHP程序,本文我们将使用FastCGI方式加载,并把过程详细记录下来方便大家参考. 常规的PHP配置方式有很多种,例如CGI.f ...

  3. [TypeStyle] Reusable styles using TypeStyle mixins

    TypeStyle’s style function allows you to give multiple objects as an argument. This provides a simpl ...

  4. php实现调整数组顺序使奇数位于偶数前面

    php实现调整数组顺序使奇数位于偶数前面 一.总结 1.array_push()两个参数,$arr在前 2.array_merge()的返回值是数组   二.php实现调整数组顺序使奇数位于偶数前面 ...

  5. pstack.sh 查看进程堆栈

    #!/bin/bash if (( $# < 1 )) then     echo "usage: `basename $0` pid" 1>&2     ex ...

  6. 洛谷 P4013 数字梯形问题

    ->题目链接 题解: 网络流. #include<cstdio> #include<iostream> #include<queue> #include< ...

  7. 如何解决安卓SDK无法下载Package的问题 分类: H1_ANDROID 2013-09-09 10:26 1199人阅读 评论(0) 收藏

    转载自:http://jingyan.baidu.com/article/8275fc86dbe84046a03cf69d.html 有些用户在安装好Android SDK后,打开Android SD ...

  8. spring 输出mvc

    http://flysnowxf.iteye.com/blog/1187580 http://viralpatel.net/blogs/spring-requestheader-example/ 基于 ...

  9. svn hook pre-commit

    #!/bin/bashexport LANG="zh_CN.UTF-8" #确保中文日志显示正常,便于统计日志REPOS="$1"TXN="$2&qu ...

  10. ajax跳转到新的jsp页面(局部刷新)

    ajax可以实现局部刷新页面,即在不刷新整个页面的情况下更新页面的局部信息. 项目中遇到一个问题:在用户列表也,当点击某个按钮时需要去查询用户的信息,查询成功跳转到用户详情界面:查询失败,则在原页面弹 ...