VB.Net Looping Issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wbosw
    New Member
    • Mar 2007
    • 36

    VB.Net Looping Issues

    I'm trying to take a word (stEAdy) and find the index positions of the uppercase characters(2,3) in the word. I have them stored in an array (positionarray) . Then I reverse the word and set all characters to lowercase. I've done that. Now, I want to take the reversed word (ydaets) and make the index positions from the array(2,3) uppercase for the reversed word, so that it will read (ydAEts). Below I'm looping thur the array incorrectly. I'm only able to get the first index position set. Any suggestions on setting up the loop correctly?

    Thanks,
    Wbosw

    Code:
     'loop thur the position array, giving the position of the capital letters in each word
                For Each Charposition As Byte In PositionArray
    
                    'set byte variable for For loop
                    Dim j As Byte
    
                    'declare Char variable to hold the actual characters
                    Dim char2 As Char
    
                    'set finalstring to nothing
                    finalString = " "
    
                    'loop thur each word to see which positions are equal to the positions in the array
                    For j = 0 To LowerRevText.Length - 1
    
                        char2 = LowerRevText.Chars(j)
    
                        'if the positions are equal then change the character to Uppercase
                        If Charposition = j Then
    
                            'change the position to uppercase
                            CapChar = Char.ToUpper(char2)
    
    	         'set char2 equal to CapChar
                            char2 = CapChar
    
                        End If
    
                        CapRevText += char2
    
                    Next
    
                    'add a space between the words
                    finalString += CapRevText + " "
    
                    'set variable = to nothing
                    CapRevText = " "
    
                Next
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    I'm unclear on what situation you want to happen based on your example

    Situation 1:
    You want to make "tReE" be "eErT"


    Situation 2:
    You want to make "tReE" be "EeRt"


    Situation 2 is just a reverse of the original string so I think you want situation 1.
    if you have the positions in an int[] (that would be {0,3} for this example)
    You would do something like this:
    Code:
    //ReverseLowerCase = original string reversed and converted to lowercase
    //ReverseUpperCase = original string reversed and converted to uppercase
    for(int i =0; i<myPosArray.Length;i++)
    {
       ReverseLowerCase[i]= ReverseUpperCase[i];
    }
    You will need to make adjustments to fit vb

    Comment

    • wbosw
      New Member
      • Mar 2007
      • 36

      #3
      My situation is like #1:

      So I want to turn ( tReEGHp) into ( pHgEERt ) that would be positions 1,3,4,5.

      would ReverseLowerCas e[i]= ReverseUpperCas e[i]; work in this situation, because it's on odd number of positions. if so, thanks in advance

      Wbosw

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Say you had:
        "TreEs"
        Then ReverseLowerCas e ="seert"
        and ReverseUpperCas e ="SEERT"
        So if you knew you wanted index 0, 3

        Then setting ReverseLowerCas e[0]=ReverseUpperCa se[0]
        would make ReverseLowerCas e="Seert";
        And setting ReverseLowerCas e[3]=ReverseUpperCa se[3]
        would make ReverseLowerCas e="SeeRt";

        Comment

        • wbosw
          New Member
          • Mar 2007
          • 36

          #5
          Thanks again Plater, you've been a great help.

          Wbosw

          Comment

          Working...