470,596 Members | 1,396 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

findign even characters odf a string?

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

Mar 9 '07 #1
9 971
On Mar 8, 7:19 pm, "Ron" <pts4...@yahoo.comwrote:
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?

--
Tom Shelton

Mar 9 '07 #2
Ron
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.
On Mar 8, 9:33 pm, "Tom Shelton" <tom_shel...@comcast.netwrote:
On Mar 8, 7:19 pm, "Ron" <pts4...@yahoo.comwrote:
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?

--
Tom Shelton

Mar 9 '07 #3
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?
"Ron" <pt*****@yahoo.comwrote in message
news:11*********************@30g2000cwc.googlegrou ps.com...
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.
On Mar 8, 9:33 pm, "Tom Shelton" <tom_shel...@comcast.netwrote:
>On Mar 8, 7:19 pm, "Ron" <pts4...@yahoo.comwrote:
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?

--
Tom Shelton

Mar 9 '07 #4
SFS
On 8 Mar 2007 18:19:13 -0800, "Ron" <pt*****@yahoo.comwrote:
>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
Mar 9 '07 #5
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

"SFS" <sf****@yahoo.comschreef in bericht
news:hp********************************@4ax.com...
On 8 Mar 2007 18:19:13 -0800, "Ron" <pt*****@yahoo.comwrote:
>>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

Mar 9 '07 #6
SFS
Thanks Cor, my mistake.

SFS

On Fri, 9 Mar 2007 06:58:28 +0100, "Cor Ligthert [MVP]"
<no************@planet.nlwrote:
>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

"SFS" <sf****@yahoo.comschreef in bericht
news:hp********************************@4ax.com.. .
>On 8 Mar 2007 18:19:13 -0800, "Ron" <pt*****@yahoo.comwrote:
>>>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
Mar 9 '07 #7
On Mar 8, 11:19 pm, "Ron" <pts4...@yahoo.comwrote:
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)

Mar 9 '07 #8
Branco,

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

Bruce

"Branco Medeiros" <br*************@gmail.comwrote in message
news:11**********************@c51g2000cwc.googlegr oups.com...
On Mar 8, 11:19 pm, "Ron" <pts4...@yahoo.comwrote:
>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)

Mar 18 '07 #9
Bruce W. Darby wrote:
<snip>
Does this algorithm take into account that the space is also a character to
the computer?
the algorithm was:
CharNumber <- 1
Buffer <- ""
For every char C in the string
If CharNumber is even then append C to Buffer
return the Buffer
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.

Mar 18 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Jacek Dziedzic | last post: by
5 posts views Thread by Angus | last post: by
28 posts views Thread by v4vijayakumar | last post: by
33 posts views Thread by Michael B Allen | last post: by
3 posts views Thread by yawnmoth | last post: by
23 posts views Thread by KIRAN | last post: by
14 posts views Thread by S | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.