2 Replies - 1561 Views - Last Post: 26 April 2011 - 08:29 AM Rate Topic: -----

#1 smiler   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-August 09

Find and Replace functionality

Posted 26 April 2011 - 02:38 AM

Hi friends, the current difficult task I am facing in my text editor project is how to include
text search and replace functionality. What i really want is for my text editor project to be
able to accept a string of characters(a word) and search through a big text string(a whole typed passage)
for words that much the given word and replace it with the new preferred word.
Now what i am currently considering is to take the whole string(typed passage) as single string and split it into
individual sub-strings(single words) by using the string.split function and delimiters like punctuations and white spaces. I will then load the words into a string array and compare each word against the given text to find and replace upon a perfect match.
I would like to know if what I'm doing is okay or anyone has a better idea to go about this. I hope my description of the task is understandable. Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Find and Replace functionality

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Find and Replace functionality

Posted 26 April 2011 - 04:29 AM

So you just want advice about your plan? You haven't even tried it?

I advise you try it and see if it works. It would have taken less time to code the 20 lines you described than it took you to write your question.

Learning through trial and error will teach you a lot more than asking others to do your thinking and experiments for you.

Don't be afraid to fail. We learn more by doing and failing than by never trying at all.

This post has been edited by tlhIn`toq: 26 April 2011 - 04:29 AM

Was This Post Helpful? 0
  • +
  • -

#3 Core   User is offline

  • using System.Linq;
  • member icon

Reputation: 784
  • View blog
  • Posts: 5,101
  • Joined: 08-December 08

Re: Find and Replace functionality

Posted 26 April 2011 - 08:29 AM

There is no need to split the string in multiple parts. There is the built in string.Replace that can be used to replace sequences but it will do that automatically without selecting the words for you. The regex way seems like a much more reliable solution - you can manually iterate through matches and select/replace them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1