By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,364 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,364 IT Pros & Developers. It's quick & easy.

VB.Net Looping Issues

P: 36
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

Expand|Select|Wrap|Line Numbers
  1.  'loop thur the position array, giving the position of the capital letters in each word
  2.             For Each Charposition As Byte In PositionArray
  3.  
  4.                 'set byte variable for For loop
  5.                 Dim j As Byte
  6.  
  7.                 'declare Char variable to hold the actual characters
  8.                 Dim char2 As Char
  9.  
  10.                 'set finalstring to nothing
  11.                 finalString = " "
  12.  
  13.                 'loop thur each word to see which positions are equal to the positions in the array
  14.                 For j = 0 To LowerRevText.Length - 1
  15.  
  16.                     char2 = LowerRevText.Chars(j)
  17.  
  18.                     'if the positions are equal then change the character to Uppercase
  19.                     If Charposition = j Then
  20.  
  21.                         'change the position to uppercase
  22.                         CapChar = Char.ToUpper(char2)
  23.  
  24.              'set char2 equal to CapChar
  25.                         char2 = CapChar
  26.  
  27.                     End If
  28.  
  29.                     CapRevText += char2
  30.  
  31.                 Next
  32.  
  33.                 'add a space between the words
  34.                 finalString += CapRevText + " "
  35.  
  36.                 'set variable = to nothing
  37.                 CapRevText = " "
  38.  
  39.             Next
Nov 9 '07 #1
Share this Question
Share on Google+
4 Replies


Plater
Expert 5K+
P: 7,872
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:
Expand|Select|Wrap|Line Numbers
  1. //ReverseLowerCase = original string reversed and converted to lowercase
  2. //ReverseUpperCase = original string reversed and converted to uppercase
  3. for(int i =0; i<myPosArray.Length;i++)
  4. {
  5.    ReverseLowerCase[i]= ReverseUpperCase[i];
  6. }
  7.  
You will need to make adjustments to fit vb
Nov 9 '07 #2

P: 36
My situation is like #1:

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

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

Wbosw
Nov 9 '07 #3

Plater
Expert 5K+
P: 7,872
Say you had:
"TreEs"
Then ReverseLowerCase ="seert"
and ReverseUpperCase ="SEERT"
So if you knew you wanted index 0, 3

Then setting ReverseLowerCase[0]=ReverseUpperCase[0]
would make ReverseLowerCase="Seert";
And setting ReverseLowerCase[3]=ReverseUpperCase[3]
would make ReverseLowerCase="SeeRt";
Nov 9 '07 #4

P: 36
Thanks again Plater, you've been a great help.

Wbosw
Nov 9 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.