原文:写一个去除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. HDU1392:Surround the Trees(凸包问题)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. 新手MFC学习之Socket练习

    事实上MFC这东西吧,好像也不光是MFC,非常多东西,事实上我如今才感觉到,假设想高速做一个东西出来的话.是没有必要系统的学关于这个东西的所有知识的.比方我想做一个MFC相似QQ的软件,可是我又不想花 ...

  3. sublime text2 基本配置及结合Python 环境

    参考: http://www.cnblogs.com/figure9/p/sublime-text-complete-guide.html http://www.zhihu.com/question/ ...

  4. 【搜索引擎Jediael开发笔记】V0.1完整代码 2014-05-26 15:16 443人阅读 评论(0) 收藏

    详细代码请见 E:\Project\[重要]归档代码\SearchEngine归档代码 或 https://code.csdn.net/jediael_lu/jediael/tree/10991c83 ...

  5. js进阶 11-21 纯css实现选项卡

    js进阶 11-21 纯css实现选项卡 一.总结 一句话总结:核心原理,a标签的锚点效果+父div限宽+多的部分隐藏. 1.如何实现a标签的锚点效果? href属性找到对应的位置就好,和选择器一样, ...

  6. [Angular Directive] Build a Directive that Tracks User Events in a Service in Angular 2

    A @Directive is used to add behavior to elements and components in your application. This makes @Dir ...

  7. ios开发多选照片实现

    #import "ViewController.h" #import <Photos/Photos.h> @interface ViewController () &l ...

  8. ant使用ssh和linux交互 如:上传文件

    http://jiajun.iteye.com/blog/741001 http://blog.csdn.net/xymyeah/article/details/4098073 http://blog ...

  9. [Javascript] Understand Function Composition By Building Compose and ComposeAll Utility Functions

    Function composition allows us to build up powerful functions from smaller, more focused functions. ...

  10. 开发自己的PHP MVC框架(一)

    这个教程能够使大家掌握用mvc模式开发php应用的基本概念.此教程分为三个部分.如今这篇是第一部分. 如今市面上有非常多流行的框架供大家使用.可是我们也能够自己动手开发一个mvc框架.採用mvc模式能 ...