3
Answers

Anyone want to tackle this or point me in thr right direction?

chad0609

chad0609

20y
5.1k
1
I can't grasp C# and need to get this done as a study tool for furture projects. I doubt it would take more than 30 minutes for someone who knows what they are doing but I just started learning C# and am still not real familiar with it. ---------------------------------------------------------------------------------------------- Some of you originally learned Visual Basic 6.0. As you may recall, VB 6.0 provided a number of functions to perform a variety of different tasks. Many, but not all, of these VB 6.0 string functions are available in VB. NET. Rather, there are classes that may have public methods. What I want you to do for this homework us create a C# class named VB6StringFunctions whose public methods provide the functionality of a number of VB 6.0 string functions. The table that follows attempts to describe the methods of this class. One note, consider the string "AB?3vfqw*HG,Sd". In all the function calls in the VB 6.0 string functions in the following table, numeric values indicating the position of a character start at 1. The, "A" in the above string is character number 1. "B" is character number 2. "?" is character number 3 and so forth. An attempt to reference character 0 (zero) would be a run-time execution error in Visual Basic 6.0. VB 6.0 Function Explanation ----- public int InStr(string sourcestring, string searchstring) Input(s): string sourcestring -- a string of characters to be searched. string searchstring -- the string of characters being sought within sourcestring. Output: a value of type int. Defined by the following: 0 if sourcestring is either null or zero length. 1 if searchstring is either null or zero length. 0 if searchstring is not found in sourcestring. i if searchstring is found in sourcestring. In this case, i is the position (one based) of the leftmost matching character of searchstring in sourcestring. For example InStr("ABCDSGDF", "D") will return the int value 4. Exception(s) Thrown: None. ----- public int InStr(string sourcestring, string searchstring, int startat) Input(s): string sourcestring -- a string of characters to be searched. string searchstring -- the string of characters being sought within sourcestring. int startat -- an int indicating the starting point of the search for searchstring. Output: a value of type int. Defined by the following: 0 if sourcestring is either null or zero length. 1 if searchstring is either null or zero length. 0 if startat is greater than the length of sourcestring 0 if searchstring is not found in sourcestring. i if searchstring is found in sourcestring. In this case, i is the position (one based) of the leftmost matching character of searchstring in sourcestring. For example InStr("ABCDSGDF", "D", 5) will return the int value 7. Exception(s) Thrown: Throws an ArgumentException if startat is less than 1. ----- public int InStrRev(string sourcestring, string searchstring) Input(s): string sourcestring -- a string of characters to be searched. string searchstring -- the string of characters being sought within sourcestring. Output: a value of type int. Defined by the following: 0 if sourcestring is either null or zero length. the Length of sourcestring if searchstring is either null or zero length. 0 if searchstring is not found in sourcestring. i if searchstring is found in sourcestring. In this case, i is the position (one based) of the leftmost matching character of searchstring in sourcestring. For example InStrRev("ABCDSGDF", "D") will return the int value 7. Exception(s) Thrown: None. ------ public int InStrRev(string sourcestring, string searchstring, int startat) Input(s): string sourcestring -- a string of characters to be searched. string searchstring -- the string of characters being sought within sourcestring. int startat -- an int indicating the starting point of the search for searchstring. Output: a value of type int. Defined by the following: 0 if sourcestring is either null or zero length. 1 if searchstring is either null or zero length. 0 if startat is greater than the length of sourcestring 0 if searchstring is not found in sourcestring. i if searchstring is found in sourcestring. In this case, i is the position (one based) of the leftmost matching character of searchstring in sourcestring. For example InStr("ABCDSGDF", "D", 5) will return the int value 4. Exception(s) Thrown: Throws an ArgumentException if startat is less than 1. ------ public string LCase(string sourcestring) Input(s): string sourcestring -- a string of characters. Output: a value of type string. Defined by the following: A string in which all uppercase characters of sourcestring have been changed to their lowercase equivalent. Exception(s) Thrown: None. ----- public string Left(string sourcestring, int howmany) Input(s): string sourcestring -- a string of characters. int howmany -- an integer defining the length of the string to be returned. Output: a value of type string. Defined by the following: "" if sourcestring is null or zero length. "" if howmany is equal to zero. sourcestring if howmany is greater than the length of sourcestring. The leftmost howmany characters of sourcestring if howmany is greater than zero and less than or equal to the length of sourcestring. For example, Left("ABCDEF", 4) returns the string "ABCD". Exception(s) Thrown: Throws an ArgumentException if the value of howmany is less than 0. ------- public int Len(string sourcestring) Input(s): string sourcestring -- a string of characters. Output: a value of type int. Defined by the following: the length (in characters) of sourcestring. Exception(s) Thrown: None. ------ public string Mid(string sourcestring, int startat) Input(s): string sourcestring -- a string of characters. int startat -- an int indicating the starting point of the substring to be returned. Output: a value of type string. Defined by the following: Returns a substring of characters starting at position startat of the string sourcestring and continuing through its rightmost character. For example, Mid("ABCDEF", 3) returns the string "CDEF". Exception(s) Thrown: Throws an ArgumentException if startat is less than 1. ------ public string Mid(string sourcestring, int startat, int howmany) Input(s): string sourcestring -- a string of characters. int startat -- an int indicating the starting point of the substring to be returned. int howmany -- an integer defining the length of the string to be returned. Output: a value of type string. Defined by the following: Returns: "" if startat is greater than the length of sourcestring. a substring of length howmany characters starting at position startat of the string sourcestring and continuing through its rightmost character, if necessary. For example, Mid("ABCDEF", 3, 3) returns the string "CDE". Exception(s) Thrown: Throws an ArgumentException if startat is less than 1. Throws an ArgumentException if howmany is less than 0. ----- public string Repeat(string sourcestring, int howmany) Input(s): string sourcestring -- a string of characters. int howmany -- an integer defining the length of the string to be returned. Output: a value of type string. Defined by the following: "" is returned if sourcestring is null or zero length. Otherwise, a string of length howmany is returned. This string is obtained by repeating the pattern of characters sourcestring as often as necessary. For example Repeat("ABDC", 10) returns the ten character string "ABCDABCDAB". Returns Exception(s) Thrown: If howmany is less than 1, this method throws an ArgumentException. ----- public string Replace(string sourcestring, string searchstring, string replacestring) Input(s): string sourcestring -- a string of characters. string searchstring -- a string of characters. string replacestring -- a string of characters. Output: a value of type string. Defined by the following: returns "" if sourcestring is null or zero length. returns sourcestring if searchstring is null or zero length. returns a string in which every occurrence of searchstring in sourcestring is replaced by an occurrence of replacestring. For example, Replace("ABCDECIJCD4", "CD", "123") returns the string "AB123ECIJ1234". While Replace("AAAAAAAA", "AAA", "D") returns the string "DDAA". Exception(s) Thrown: ------ public string Right(string sourcestring, int howmany) Input(s): string sourcestring -- a string of characters. int howmany -- an integer defining the length of the string to be returned. Output: a value of type string. Defined by the following: If howmany is zero, the string "" is returned. If howmany is greater than the length of sourcestring, sourcestring is returned. Otherwise, the rightmost howmany characters of sourcestring is returned. Exception(s) Thrown: Throws an ArgumentException if howmany is less than zero ------ public string Space(int howmany) Input(s): int howmany -- an integer defining the length of the string to be returned. Output: a value of type string. Defined by the following: if howmany is zero, returns "". Otherwise, returns a string composed of howmany spaces. Exception(s) Thrown: Throws an ArgumentException if howmany is less than zero ------ public string String(string sourcestring, int howmany) Input(s): string sourcestring -- a string of characters. int howmany -- an integer defining the length of the string to be returned. Output: a value of type string. Defined by the following: If howmany is zero, returns the string "". Otherwise, returns a string of length howmany occurrences of the leftmost character of sourcestring. Exception(s) Thrown: Throws an ArgumentException if howmany is less than zero ----- public string strReverse(string sourcestring) Input(s): string sourcestring -- a string of characters. Output: a value of type string. Defined by the following: If sourcestring is null or zero length, "" is returned. Otherwise, the returned string is obtained by reversing the order of the characters of sourcestring. For example, strReverse("ABCD") returns "DCBA". Exception(s) Thrown: None. ------ public string UCase(string sourcestring) Input(s): Output: a value of type string. Defined by the following: Returns a string in which all lowercase characters in sourcestring are replaced by their uppercase equivalent. UCase("abcDE123") returns "ABCDE123". Exception(s) Thrown: None. You are to create a new C# project that is a Class Library. To do this follow these steps: Start the Visual Studio .NET 2003. Click the New Project button on the start page. Make certain the Project Type is Visual C# Projects and that you use the template Class Library. Name the project VB6StringFunctions. Repeat: name the project VB6StringFunctions. Any other name and your code will not work correctly. Feel free to put it in any location that you wish on your PC. If you do all of this correctly, you should be taken directly to the code window where you should see the following using System; namespace VB6StringFunctions { /// /// Summary description for Class1. /// public class Class1 { public Class1() { // // TODO: Add constructor logic here // } } } This code has been generated for you by Visual Studio. You need to make one change to it before you start. Change the two occurrences of Class1 to OurString. Yes, capitalization matters in this name and all the other names you use anywhere. What you've done is to create a NameSpace VB6StringFunctions which contains a single public class named OurString. The code you place into this class becomes a part of the class. So let's add a little code to your class. Type the following into the code window, immediately after line 15. That's the line of code containing the } character that terminates the Class1 Constructor. public string LCase(string sourcestring) { return sourcestring.ToLower(); } If you Debug Start this project, you will be informed that a Class cannot be executed. However, a quick check of your disk drive will show a dll file has been generated in the folder bin\Debug. This Dynamic Link Library (dll) contains all the code required to allow other programs to to use the Methods (and Properties or Events, if any) of the class OurString. To test out the dll, go to the Solution Explorer window. Select and then right click the current solution. From the context sensitive menu, choose Add and then New Project. Create a VB Windows Application. Go back to the Solution Explorer and locate the project you just added to the solution. Below it, you will find its references. Right click the references and choose Add Reference. From the dialog window that appears, choose the Projects tab. Click Browse and find the dll file on your PC. Add this as a reference to your project. Next, back in the Solution Explorer, select and then right click the solution. Choose Properties. In the dialog window, select the single startup project option. From the DropDown List, choose the VB project you just added to the solution. Go to the code window for this new project and make the first two statements be Option Explicit On Imports VB6StringFunctions Finally, view the VB form in design mode. Add a single Button to the form. Generate a Click event handler for the button. Copy these two executable statements to the click event, run the solution and click the button. Dim A As New OurString Dim B As String = "SOme Caps in Here" MessageBox.Show(A.LCase(B)) If everything works correctly, you will see the string value returned by the OurString LCase method for the input "SOme Caps in Here". When the VB form appears, put a Button on it and double click the Button. In the design window, enter the following two statements int he Button Click event. For this homework, you are to implement all of the Methods of the Class OurString as described in the above table. Because of the importance of naming and capitalization conventions, here is a skeleton for the class and its methods. You can simply copy this and paste it into your class. You'll have to add appropriate code to implement the methods except for LCase(), which is coded below. using System; namespace VB6StringFunctions { /// /// Summary description for Class1. /// public class OurString { public OurString() { // // TODO: Add constructor logic here // } public int InStr(string sourcestring, string searchstring) { } public int InStr(string sourcestring, string searchstring, int startat) { } public int InStrRev(string sourcestring, string searchstring) { } public int InStrRev(string sourcestring, string searchstring, int startat) { } public string LCase(string sourcestring) { } public string Left(string sourcestring, int howmany) { } public int Len(string sourcestring) { } public string Mid(string sourcestring, int startat) { } public string Mid(string sourcestring, int startat, int howmany) { } public string Repeat(string sourcestring, int howmany) { } public string Replace(string sourcestring, string searchstring, string replacestring) { } public string Right(string sourcestring, int howmany) { } public string Space(int howmany) { } public string String(string sourcestring, int howmany) { } public string strReverse(string sourcestring) { } public string UCase(string sourcestring) { } } } Attempting to compile the above will fail because only the LCase() Method has a return statement. You can comment out all Methods except LCase() and find that you can compile the class.
Answers (3)