-8

This program prints all words in the textarea if there is ed. I need to print all words in the textarea that end with ed.

<html>
<head>
<title></title>
<script type = "text/javascript">
function testString()
{
var myForm = document.getElementById( "myForm" );
var s = myForm.input.value;
if ( s.substr( s.length - 2, 2 ) == "ed" )
myForm.output.value += s + "\n";
}
</script>
</head>
<body>
<form id = "myForm" >
<textarea name = "input" rows = "10" cols = "55"></textarea><br />
<input type = "button" value = "Submit" onclick = "testString()" /><br />
<textarea name = "output" rows = "10" cols = "55"></textarea>
</form>
</body>
</html>
  • MSDN is very good starting point to investigate problems. I.e. searching for https://www.bing.com/search?q=c%23+Console.ReadLine should give you some explanation about what `ReadLine` actually doing and it hopefully will help to understand your code... Debugging is second steps - hopefully when you finish you are close to solution, or at least can update question to make it more concrete. – Alexei Levenkov Apr 21 '15 at 21:15
  • Stop marking him down and give the guy a chance to clarify the question. – Dave Gordon Apr 21 '15 at 21:19
  • Please improve the question: If you have multiple different questions, think of starting a new topic for each. What is your programming the problem? What are you trying to achieve? Why couldn't you achieve it so far? What did you try? – Rias Apr 21 '15 at 21:30
  • The question is written above how to improve the question ? @Rias – Taoufic Hijazi Apr 21 '15 at 21:33
  • I don't understand the context of your questions. It looks like three (or more) questions to me. – Rias Apr 21 '15 at 21:36

1 Answers1

0

The difference between the arrays:

The difference between double[] array = new double[a.Count - 2]; and double[] array = new double[a.Count]; is the length of the array you are declaring. When you are passing a integer value into the constructor of your new array that is the length your array will be initialized with.

Notes on array declaration and length:

This length cannot be changed after declaration and you must create a new array and copy elements to the new collection.

Value vs reference comparison:

As for your comparisons throughout your method, there is two primary forms of comparison, comparison by value and comparison by reference. Comparison by value returns true if the value of two objects (int, string, etc.) are the same. Comparison by reference returns true if two variables point to the same place in memory. You should be using the .Equals() method instead of "==", this will assure you are comparing by value and not by reference.

Further Notes:

Also something to note that you will have to go out and research for yourself is length and count are not the same. The difference is covered here.

Community
  • 1
  • 1
CalebB
  • 597
  • 3
  • 16