原文:写一个去除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. 2.3系列系统中不支持SimpleDateFormat作字段被序列化

    安卓问题记录:在2.3系列系统中不支持SimpleDateFormat作字段被序列化,使用时需要将SimpleDateFormat作临时变量使用.

  2. PWA之Web 应用清单

    原文 简书原文:https://www.jianshu.com/p/5c96242188e8 大纲 1.什么是Web 应用清单 2.“清单文件”:Web App Manifest 规范的应用 3.we ...

  3. Vue源码--深入模板渲染

    原文链接:https://geniuspeng.github.io/2018/02/07/vue-compile/ 之前整理了vue的响应式原理,在这里有一点是一直很模糊的,就是何时去new一个wat ...

  4. 【31.72%】【codeforces 604B】More Cowbell

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. Java 学习(21):Java 实例

    Java 实例 本章节我们将为大家介绍 Java 常用的实例,通过实例学习我们可以更快的掌握 Java 的应用. Java 环境设置实例 //HelloWorld.java 文件 public cla ...

  6. JSON入门之二:org.json的基本用法 分类: C_OHTERS 2014-05-14 11:25 6001人阅读 评论(0) 收藏

    java中用于解释json的主流工具有org.json.json-lib与gson,本文介绍org.json的应用. 官方文档: http://www.json.org/java/ http://de ...

  7. 【27.22%】【poj2991】Crane

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5772   Accepted: 1571   Special Judge D ...

  8. Birt

    http://www.eclipse.org/birt/ 咖啡图 http://www.kafeitu.me/activiti/2012/05/26/kft-activiti-demo.html

  9. OpenGLES 关于 数学 的分支 - 线性变化量、离散量、随机量

    关于 数学 的分支 - 线性变化量.离散量.随机量 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作 ...

  10. UItableview正在滚动的时候进行操作容易出问题

    tableview正在滚动的时候进行其它点击事件操作容易出问题,有时候会出现莫名其妙的数组越界的bug, 解决方法:1.对objectatindex方法进行异常判断 2. [_tableview se ...