472,353 Members | 998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 1078
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mo | last post by:
Hi, I am trying to write a code to build a string 768 characters long. This string is going to be written to a file which is then read by...
11
by: Jacek Dziedzic | last post by:
Hi! I need a routine like: std::string nth_word(const std::string &s, unsigned int n) { // return n-th word from the string, n is 0-based //...
5
by: Angus | last post by:
Hello I am using ifstream to load the contents of a text file into a char* variable. I am allocating using new with the file size as amount to...
15
by: nagar | last post by:
I need to split a string whenever a separator string is present (lets sey #Key(val) where val is a variable) and rejoin it in the proper order...
28
by: v4vijayakumar | last post by:
#include <string> #include <iostream> using namespace std; int main() { string str; str.resize(5); str = 't';
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the...
3
by: yawnmoth | last post by:
Say I had .a.b.c and wanted to return abc. Any ideas as to how I'd do this? Here's my attempt, but it doesn't work: <?php echo...
23
by: KIRAN | last post by:
Hi all, can i split a C string like this? char * p = "Hello \ World\n\r"; is this according to standard? Any help or link to standard regarding...
14
by: S | last post by:
Any idea on how I would be able to do a search within C# that does ranges or words For example I want to search for Chicken in the string ...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.