hoTools.Find.FindAndReplace.ChangeString C# (CSharp) 메소드

ChangeString() 공개 메소드

Change strings of items to the stored 'newString' value. Optional you may use your own 'newString' parameter.
public ChangeString ( string stringToChange, string newString = "" ) : string
stringToChange string
newString string "Change the found values to 'neString'."
리턴 string
        public string ChangeString(string stringToChange,  string newString="")
        {
            if (newString == "") newString = _replaceString;
            Match match = _regExPattern.Match(stringToChange);
            int replacedCharactersCount = 0;
            while (match.Success)
            {
                int posStartMatch = match.Index - replacedCharactersCount ;
                int lengthMatch = match.Length;
                replacedCharactersCount = replacedCharactersCount + match.Length - newString.Length;
                stringToChange = stringToChange.Remove(posStartMatch, lengthMatch);
                stringToChange = stringToChange.Insert(posStartMatch, newString);


                match = match.NextMatch();
                
            }
            return stringToChange; 
        }
        #endregion

Usage Example

        private void btnChange_Click(object sender, EventArgs e)
        {
            if (_fr.Index >= 0)
            {
                FindAndReplaceItem item = _fr.LItems[_fr.Index];
                item.Name        = _fr.ChangeString(item.Name, txtTo.Text);
                item.Description = _fr.ChangeString(item.Description, txtTo.Text);
                item.Stereotype  = _fr.ChangeString(item.Stereotype, txtTo.Text);
                // update form
                rtfName.Text       = item.Name;
                rtfNotes.Text      = item.Description;
                rtfStereotype.Text = item.Stereotype;

                //
                if (_fr.IsTagSearch && (gridTags != null))
                {
                    gridTags.DataSource = null;
                    //FindAndReplaceItemElement itemEl = (FindAndReplaceItemElement)item;
                    foreach (FindAndReplaceItemTag tag in item.LItemTag)
                    {
                        tag.Value = _fr.ChangeString(tag.Value, txtTo.Text);
                    }
                    gridTags.AutoGenerateColumns = false;
                    gridTags.DataSource          = item.LItemTag;
                }
            }
            txtState.Text = StateCurrentItem() + @" changed temporary, store if you want it permanently.";
        }
All Usage Examples Of hoTools.Find.FindAndReplace::ChangeString