Link to home
Start Free TrialLog in
Avatar of nosurf2day
nosurf2day

asked on

Exam coming up, I have questions I need help answering.

I have an upcoming exam and I don't have access to my professor and I have questions that the book is not clarifying for me.  The book that the class is using is Murach's Visual Basic 2008.

iI will list the questions will by numbers.  I understand that there are alot of questions here but I really need a good grade on this exam and these are the areas that I am still unsure of.  Some of the questions, I have tried to answer and I posted a comment in (), it my guess is correct could you annotate so.  If not could you help me get on base.

I am taking the exam tomorrow at 11.  I have been buried in this book for a couple of days now and I need help.  I am using this site as a last resort.  I figured individuals on here are much more proficient than myself so I mine as well ask the experts.  

I want to thank anyone in advance that is willing to answer any of these questions for me.  God Bless and Happy Veterans Day.  I myself am an "Iraq Veteran" in 2003.

13.  Code that uses the IndexOf method  (THE PROFESSOR POSTED THE COMMENTS AT THE END OF EACH STATEMENT, I DONT UNDERSTAND WHAT HE IS REFERRING TO THOUGH)
Dim companyName As String = "Mike Murach and Associates"
Dim index1 As Integer = companyName.IndexOf(" ")     ' 4 (IS THIS NOTING WHERE THE FIRST SPACE IS
                                                                                              AND REFERERENCING IT'S POINT AS INDEX1?)
Dim index2 As Integer = companyName.IndexOf("Inc.")  ' -1 (THIS ISN'T IN THE COMPANY NAME AT THIS
                                                                                                 POINT SO I AM CONFUSED?)
Dim index3 As Integer = companyName.LastIndexOf(" ") ' 15 (THIS IS REFERENCING THE THIRD SPACE
                                                                                                   AFTER THE AND?)

Dim index4 As Integer = companyName.IndexOf(a)   ??  (THIS IS REFERENCING THE FIRST LETTER A?
                                                                                               WHAT ANNOTATES IF ITS NOT THE FIRST  
                                                                                               LETTER A, AND IS REFERING TO THE FIRST
                                                                                               WORD WITH FIRST LETTER A? )
Dim index5 As Integer = companyName.LastIndexOf(a) ?? (BASED ON THE FIRST REFERENCE I AM
                                                                                                  GUESSING THAT IT IS REFERRING TO THE
                                                                                                  LAST WORD WITH THE FIRST LETTER A IN
                                                                                                  THE STRING?)

Code that uses the Remove, Insert, and Replace methods
companyName = companyName.Remove(0, index1 + 1)  ?? (DOES THIS SAY REMOVE THE FIRST
                                                                                                 WORD, "MIKE"?)

companyName
   = companyName.Insert(companyName.Length, ", Inc.") ??   (DOES THIS SAY INSERT "Inc." AT THE
                                                                                                    END OF THE COMPANY NAME?)

companyName _
    = companyName.Replace("and", "And")
                            ' Murach And Associates, Inc.                       (THIS CODE IS JUST SAYING REPLACE
                                                                                                    ONE DESIGNATED WORD FOR
                                                                                                   ANOTHER?)

companyName = companyName.Insert(companyName.IndexOf(and),  JJ)   ??  (THIS CODE IS SAYING
                                                                                                                                    INSERT "JJ" IN THE
                                                                                                                                   PLACE OF "and"?)



14.  Code that copies one string to another string
Dim s1 As String = "abc"
Dim s2 As String = s1
         ' This creates a new string with the value "abc"
s2 = "def"
         ' This doesn't change the value stored in s1
          s1 ??  

Answer: (abc?)

15.  Application Examples: (1) Code that parses a first name from a name string

Dim fullName As String = " Edward C Koop   "       

fullName = fullName.Trim   'fullname ??      

Answer:     ( "Edward C Koop"?)

Dim firstSpace As Integer = fullName.IndexOf(" ")   ' 6          (FIRST SPACE?)
Dim firstName As String = ""   

If firstSpace = -1 Then
    firstName = fullName        ??  (THIS STATEMENT COMPLETELY CONFUSES ME?)
Else
    firstName = fullName.Substring(0, firstSpace)  ??  (THIS STATEMENT IS SAYING REMOVE THE FIRST
                                                                                      SPACE?)
End If
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Litlte clarrification of 14:
a) Dim fullName As String = " Edward C Koop   "       
    fullName = fullName.Trim
    FullName will be: "Edward C Koop"
The trim-function removes the trailing and leading spaces in a string

b)
If firstSpace = -1 Then
    firstName = fullName
Else
    firstName = fullName.Substring(0, firstSpace)  
End If
--> If there is a space in the fullname, the firstname will only be filled with the text before the space. If there is no space in the name, it will be filled with the complete name:
Example:
Name = "Edward C Koop" --> firstname = "Edward"
Name = "Edward_C_Koop" --> firstname="Edward_C_Koop"
Clarification of 14
Dim s1 As String = "abc"
Dim s2 As String = s1
s2 = "def"
Solution:
s1 = "abc"
s2 = "def"
Dim companyName As String = "Mike Murach and Associates"
Dim index1 As Integer = companyName.IndexOf(" ")  
Dim index2 As Integer = companyName.IndexOf("Inc.")  

Solution
index1 = 4   --> if we take a look at the string of the companyname, we'll notice that on the fourt position, there is a space
index2 = -1 --> in the companyname, we don't find a substring ("inc."). If it's not there, the indexOf-function will return -1

For more information about
indexOf: http://msdn.microsoft.com/en-us/library/system.string.indexof.aspx
insert: http://msdn.microsoft.com/en-us/library/system.string.insert.aspx
Avatar of nosurf2day
nosurf2day

ASKER

Clarification of 14
Dim s1 As String = "abc"
Dim s2 As String = s1
s2 = "def"
Solution:
s1 = "abc"
s2 = "def"

What does this statement mean then? Dim s2 As String = s1

To me it is saying that s2 is now equal to s1 which is abc,  but then it defines s2 as being def so does that change what the other statement is saying
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial