使用替换更改数字

时间:2013-05-05 15:47:05

标签: c# regex methods replace

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace AnchorChanger
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dosyalar_Click(object sender, EventArgs e)
        {
            txtdosyalar.Text = "";
            int dosyasayisi = 0;
            openFileDialog1.Multiselect = true;
            openFileDialog1.ShowDialog();
            foreach (string str in openFileDialog1.FileNames)
            {
                txtdosyalar.Text += str + "\r\n";
                dosyasayisi += 1;
            }
            txtdosyalar.Text += "Total " + dosyasayisi + " file will be process";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int islemsay = 0;
            foreach (var str in openFileDialog1.FileNames)
            {
                string isle = File.ReadAllText(str);
                File.WriteAllText(str, isle);
                islemsay = islemsay + 1;
                for (int i = 0; i < 500; i++)
                {
                    string si = i.ToString();
                    string degistirilen = "<a href=\"#_ftn"+si+"\" name=\"_ftnref"+si+"\" title=\"\" id=\"_ftnref"+si+"\">";
                    string degisim = "<a href=\"#_ftn"+si+"\" name=\"_ftnref"+si+"\" title=\"\" id=\"_ftnref"+si+"\"><SUP>"+si+"</SUP>";
                    File.WriteAllText(str, isle.Replace(degistirilen, degisim));
                }
            };

            txtdeisim.Text += islemsay + " file processed" + "\r\n";
        }



    }
}

问题很简单。我有一个项目,我必须在HTML中设置数千锚。所以我想改变它并将数字设置为锚点。 程序将改变这一点。程序不将整数i与字符串str进行比较。我尝试使用字符串si = i.ToString();但没有奏效。

For example this
<a href="#_ftn3" name="_ftnref3" title="" id="_ftnref3">

Will be change like this :
<a href="#_ftn3" name="_ftnref3" title="" id="_ftnref3"><SUP>3</SUP>

我试图使用正则表达式但没有工作或我不能。我在等你的帮忙。谢谢

0 个答案:

没有答案