954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem in highlighting wrong words

hi guys,
Does anyone knows how to highlight the words that are wrong at string str2 when compared to string str1? Below is my coding. Thanks.

string str1 = "This is an good example, i like it.";
string str2 = "This is a bad example, i dislike it.";
str1.Split(' ', ',', '.');
str2.Split(' ', ',', '.');
int i = 0, error = 0;
int intWordLength = str1.Split(' ', ',', '.').Length;
while (i < intWordLength)
{
if (!str1.Split(' ', ',', '.')[i].Equals(str2.Split(' ', ',', '.')[i]))
error++;
i++;
}
Response.Write(error.ToString());

darren_88
Newbie Poster
3 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Hi fri, could you please use

put your code here


tags if you want to get reply from others . It maintains the formatting to make it easier to read your code.

octavia
Light Poster
48 posts since Jan 2008
Reputation Points: 10
Solved Threads: 1
 
string str1 = "This is an good example, i like it.";
string str2 = "This is a bad example, i dislike it.";
str1.Split(' ', ',', '.');
str2.Split(' ', ',', '.');
int i = 0, error = 0;
int intWordLength = str1.Split(' ', ',', '.').Length;
while (i < intWordLength)
{
if (!str1.Split(' ', ',', '.')[i].Equals(str2.Split(' ', ',', '.')[i]))
error++;
i++;
}
Response.Write(error.ToString());
darren_88
Newbie Poster
3 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

ok thx dude.

darren_88
Newbie Poster
3 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Strings are an imuutable type. You dont directly change their value, you assign a new value to them. As such, their functions do not change their value. For example:

class Program
    {
        static void Main(string[] args)
        {
            string test = "This is a test";
            Console.WriteLine("Initial value: {0}", test);

            test.Replace(" ", "_");
            Console.WriteLine("Value after method: {0}", test);

            test = test.Replace(" ", "_");
            Console.WriteLine("Value after method and assignment: {0}", test);

            Console.ReadKey();
        }

    }


So when you call str2.Split it doesnt make any changes to str1. Split is a method which returns an array of strings. You need to store the array that each split method returns and compare the elements of the arrays.
Try rewriting it and let us know where you get to.

Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: