findign even characters odf a string?

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

How would I go about finding the even characters in a string? for
example:

string = I have so it would return even characters of ae

thanks
 
How would I go about finding the even characters in a string? for
example:

string = I have so it would return even characters of ae

thanks

Ron forgive me, but what exactly are you asking for? Even in what
way?
 
ok for example I have this string:
This is my string

I want it to return the even characters of this string aso it would
return:
hsiysrn
anythi gin a 2 or 4 or 6 etc position

I was thinking of doing it something like this:

dim string1 as String = txtstring.text
dim evens as string
if evens mod 2 then true
else false

txtoutput.text = evens

But I dont know how to do this at all. I am thinking there will be a
loop of some kind and someway that it will pull out the 2nd, 4th, 6th
character etc.
 
Tom was really asking:

What is the reason for wanting to do this?

For exaample:

Is it an actual requirement in an actual specification for an actual
application?

or

Is it a homework assignment for a course?

or

Is it something you just want to do for no reason at all?
 
How would I go about finding the even characters in a string? for
example:

string = I have so it would return even characters of ae

thanks

For Count = 2 To TextBox1.Text.Length Step 2
TextBox2.Text = TextBox2.Text & Mid(TextBox1.Text, Count,1)
Next

Not pretty, but it should work.

SFS
 
SFS,

We have the not written appointment in this newsgroup between regulars not
to do homework for scholars.

Your message is 5 minutes after the one from Stephany, but this seems so
much homework that we are used to sent a message like Stepahany did.

We will be glad if you do the same next time.

Cor
 
Thanks Cor, my mistake.

SFS

SFS,

We have the not written appointment in this newsgroup between regulars not
to do homework for scholars.

Your message is 5 minutes after the one from Stephany, but this seems so
much homework that we are used to sent a message like Stepahany did.

We will be glad if you do the same next time.

Cor
 
How would I go about finding the even characters in a string? for
example:

string = I have so it would return even characters of ae

thanks

The algorithm goes like this:

CharNumber <- 1
Buffer <- ""
For every char C in the string
If CharNumber is even then append C to Buffer
return the Buffer

HTH.

Regards,

Branco
(sighs)
 
Branco,

Does this algorithm take into account that the space is also a character to
the computer?

Bruce
 
Bruce W. Darby wrote:
Does this algorithm take into account that the space is also a character to
the computer?

the algorithm was:

Yep, but notice the algorithm is wrong (ouch!). I forgot to increment
CharNumber inside the loop (damn, I keep doing that). The corrected
algorithm would be:

CharNumber <- 1
Buffer <- ""
For every char C in the string
If CharNumber is even then append C to Buffer
Increment CharNumber
return the Buffer

And that would lead to the following code (I assume the orignal
homework already passed its due time, so let's enlighten the OP)

Function EvenChars(Text As String) As String
Dim CharNumber As Integer = 1
Dim Buffer As New System.Text.StringBuilder
For Each C As Char In Text
If CharNumber Mod 2 = 0 Then
Buffer.Append(C)
End If
CharNumber += 1
Next
Return Buffer.ToString
End Function

Regards,

Branco.
 
Back
Top