public void Should_be_able_to_replace_word()
        {
            var replaceWord = new ReplaceWord(new Dictionary <string, string> {
                { "foo", "newWord" }
            });
            var execute = replaceWord.Manipulate("Hello foo");

            execute.Should().Be("Hello newWord");
        }
        public void FindAndReplace_ReturnString_ReplaceWord()
        {
            string sentence    = "The man said hi";
            string word        = "hi";
            string replaceWord = "hello";
            string result      = ReplaceWord.FindAndReplace(sentence, word, replaceWord);

            Assert.AreEqual("The man said hello", result);
        }
Exemple #3
0
 public void Initialize(ISpellingChecker spellingChecker, MshtmlControl mshtmlControl,
                        IHTMLDocument2 htmlDocument, ReplaceWord replaceWordFunction, MarkupRangeFilter filter, DamageFunction damageFunction)
 {
     _spellingChecker     = spellingChecker;
     _mshtmlControl       = mshtmlControl;
     _htmlDocument        = htmlDocument;
     _filter              = filter;
     _replaceWordFunction = replaceWordFunction;
     _damageFunction      = damageFunction;
 }
 public void Initialize(ISpellingChecker spellingChecker, MshtmlControl mshtmlControl,
     IHTMLDocument2 htmlDocument, ReplaceWord replaceWordFunction, MarkupRangeFilter filter, DamageFunction damageFunction)
 {
     _spellingChecker = spellingChecker;
     _mshtmlControl = mshtmlControl;
     _htmlDocument = htmlDocument;
     _filter = filter;
     _replaceWordFunction = replaceWordFunction;
     _damageFunction = damageFunction;
 }
Exemple #5
0
        public static void Main()
        {
            Console.Write("Enter a sentence: ");
            string sent = Console.ReadLine();

            Console.Write("Enter the word you want replaced: ");
            string word = Console.ReadLine();

            Console.Write("Enter the word you want to replace it with: ");
            string replaceWord = Console.ReadLine();

            Console.WriteLine(ReplaceWord.FindAndReplace(sent, word, replaceWord));
        }
	static void Init () 
	{
		win = ScriptableObject.CreateInstance( typeof(ReplaceWord) ) as ReplaceWord;
		win.ShowUtility();			
	}
Exemple #7
0
    private DataView CreateDataView(ReplaceWord[] aRW)
    {
        DataView dv = new DataView();
        System.Web.UI.WebControls.BoundColumn colBound = new System.Web.UI.WebControls.BoundColumn();

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "OldWord";
        colBound.HeaderText = base.GetMessage(GetHeaderString("lbl old word"));
        dgReplace.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "NewWord";
        colBound.HeaderText = base.GetMessage(GetHeaderString("lbl new word"));
        dgReplace.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "Regex";
        colBound.HeaderText = base.GetMessage(GetHeaderString("lbl regex"));
        colBound.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
        colBound.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
        dgReplace.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "Language";
        colBound.HeaderText = base.GetMessage(GetHeaderString("generic language"));
        dgReplace.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "ID";
        colBound.HeaderText = base.GetMessage(GetHeaderString("generic id"));
        dgReplace.Columns.Add(colBound);

        if (m_iBoardID == 0 && !bIsEmoticon)
        {
            colBound = new System.Web.UI.WebControls.BoundColumn();
            colBound.DataField = "AppliesTo";
            colBound.HeaderText = base.GetMessage(GetHeaderString("lbl applies to"));
            dgReplace.Columns.Add(colBound);
        }

        DataTable dt = new DataTable();
        DataRow dr;

        dt.Columns.Add(new DataColumn("OldWord", typeof(string)));
        dt.Columns.Add(new DataColumn("NewWord", typeof(string)));
        dt.Columns.Add(new DataColumn("Regex", typeof(string)));
        dt.Columns.Add(new DataColumn("Language", typeof(string)));
        dt.Columns.Add(new DataColumn("ID", typeof(string)));
        dt.Columns.Add(new DataColumn("AppliesTo", typeof(string)));

        for (int i = 0; i <= (aRW.Length - 1); i++)
        {
            dr = dt.NewRow();
            if (bIsEmoticon)
            {
                dr[0] = "<a style=\"text-decoration: none\" href=\"replacewords.aspx?action=view&boardid=" + this.m_iBoardID.ToString() + "&id=" + aRW[i].ID.ToString() + "&isemoticon=" + Convert.ToInt32(bIsEmoticon) + "\">" + aRW[i].OldWord.Replace("\\", "") + "</a>";
            }
            else
            {
                dr[0] = "<a href=\"replacewords.aspx?action=view&boardid=" + this.m_iBoardID.ToString() + "&id=" + aRW[i].ID.ToString() + "&isemoticon=" + Convert.ToInt32(bIsEmoticon) + "\">" + aRW[i].OldWord + "</a>";
            }
            dr[1] = "<a href=\"replacewords.aspx?action=view&boardid=" + this.m_iBoardID.ToString() + "&id=" + aRW[i].ID.ToString() + "&isemoticon=" + Convert.ToInt32(bIsEmoticon) + "\">" + ConditionalMakeImage(aRW[i].NewWord) + "</a>";
            dr[2] = "<input type=\"checkbox\" " + ((aRW[i].IsRegex == true) ? " checked " : "") + " disabled />";
            dr[3] = "<img src=\'" + objLocalizationApi.GetFlagUrlByLanguageID(aRW[i].LanguageID) + "\' border=\"0\" />";
            dr[4] = "<a href=\"replacewords.aspx?action=view&boardid=" + this.m_iBoardID.ToString() + "&id=" + aRW[i].ID.ToString() + "&isemoticon=" + Convert.ToInt32(bIsEmoticon) + "\">" + aRW[i].ID.ToString() + "</a>";
            if (m_iBoardID == 0)
            {
                for (int j = 0; j <= (aRW[i].AppliesTo.Length - 1); j++)
                {
                    dr[5] += "<img valign=\'center\' src=\'" + m_refContentApi.AppImgPath + "menu/users2.gif" + "\' />&nbsp;<a href=\"../content.aspx?action=ViewContentByCategory&id=" + aRW[i].AppliesTo[j].Id.ToString() + "\">" + aRW[i].AppliesTo[j].Name + "</a>";
                    if (j < aRW[i].AppliesTo.Length)
                    {
                        dr[5] += "<br/>";
                    }
                }
            }
            dt.Rows.Add(dr);
        }
        dv = new DataView(dt);
        return dv;
    }
Exemple #8
0
    public void Process_AddEdit()
    {
        try
        {
            if (this.m_iID > 0)
            {
                aReplace = cContent.SelectReplaceWord(this.m_iID, bIsEmoticon);
                rwReplace = aReplace[0];
            }
            else
            {
                rwReplace = new ReplaceWord();
            }
            rwReplace.OldWord = EkFunctions.HtmlEncode(Request.Form[txt_old.UniqueID]).Trim();
            rwReplace.NewWord = EkFunctions.HtmlEncode(Request.Form[txt_new.UniqueID]).Trim();
            rwReplace.IsRegex = System.Convert.ToBoolean(chk_regex.Checked);
            rwReplace.LanguageID = Convert.ToInt32(drp_lang.SelectedValue);

            if (m_iBoardID > 0 || bIsEmoticon)
            {
                rwReplace.AppliesTo = (FolderData[])Array.CreateInstance(typeof(FolderData), 1);
                rwReplace.AppliesTo[0] = new FolderData();
                rwReplace.AppliesTo[0].Id = this.m_iBoardID;
            }
            else if (drp_boards.Items.Count > 0)
            {
                rwReplace.AppliesTo = (FolderData[])Array.CreateInstance(typeof(FolderData), 1);
                rwReplace.AppliesTo[0] = new FolderData();
                rwReplace.AppliesTo[0].Id = Convert.ToInt64(drp_boards.SelectedValue);
            }
            Response.Write(rwReplace.LanguageID.ToString());
            rwReplace = cContent.AddEditReplaceWord(rwReplace, Convert.ToBoolean(bIsEmoticon));
            if (this.m_iID > 0) // edit
            {
                Response.Redirect((string)("replacewords.aspx?boardid=" + this.m_iBoardID.ToString() + "&action=view&id=" + this.m_iID.ToString() + "&isemoticon=" + Convert.ToInt32(bIsEmoticon)), false);
            }
            else // add
            {
                Response.Redirect((string)("replacewords.aspx?boardid=" + this.m_iBoardID.ToString() + "&isemoticon=" + Convert.ToInt32(bIsEmoticon)), false);
            }
        }
        catch (Exception ex)
        {
            Utilities.ShowError(ex.Message);
        }
    }