Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8940169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:58:39+00:00 2026-06-15T10:58:39+00:00

byte[] ASCIIValues = Encoding.ASCII.GetBytes(myInput); while (I < ASCIIValues.Length) { { if ((ASCIIValues[I] > 65

  • 0
byte[] ASCIIValues = Encoding.ASCII.GetBytes(myInput);    
while (I < ASCIIValues.Length)
{
    {
        if ((ASCIIValues[I] > 65 & ASCIIValues[I] < 90) || (ASCIIValues[I] > 97 & ASCIIValues[I] < 122))
        {

        }
        ASCIIValues[I] = 32;
    }
    Console.WriteLine(ASCIIValues[I]);
    I++;
}

This is what I have now and I am trying to make sure the string the user enters (my Input) is within the ranges of being a letter only. I am trying to remove all punctuation and special characters as well as numbers. I is equal to 0 and is used to iterate through the array. Changing all unwanted characters to a space is because further down in my code I am removing the spaces anyway.

When running the code every returned ASCII value is 32. This makes no sense as letters should return the corresponding ASCII value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:58:40+00:00Added an answer on June 15, 2026 at 10:58 am

    (As L.B says, there are simpler ways of doing this – but it’s worth examining why your current code doesn’t work, too.)

    When running the code every returned ASCII value is 32

    Yes, it would do. Look closely at your loop:

    while (I < ASCIIValues.Length)
    {
        {
            if ((ASCIIValues[I] > 65 & ASCIIValues[I] < 90) || (ASCIIValues[I] > 97 & ASCIIValues[I] < 122))
            {
    
            }
            ASCIIValues[I] = 32;
        }
        Console.WriteLine(ASCIIValues[I]);
        I++;
    }
    

    You’re doing nothing within the if block, and instead you’re unconditionally setting ASCIIValues[I] to 32.

    Additionally:

    • I’d use a for loop rather than a while loop.
    • You don’t really need to convert the characters to bytes here; each ASCII character has the same Unicode value anyway.
    • Specifying the characters using character literals ('A' etc) would make the code simpler to read
    • You should adopt .NET naming conventions to make your code more idiomatic
    • You should use && instead of & here
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

foreach (byte binaryOutupt in Encoding.ASCII.GetBytes(fileLine)) { fileOutput.Write(binaryOutupt.ToString(x2)); } I got this code which let
I have a byte array and I need to convert this to a image.
Possible Duplicate: byte + byte = int… why? I have a method like this:
I have a byte array similar to this (16 bytes): 71 77 65 72
I have a byte[] testKey = new byte[8]; This obviously starts with all bytes
public byte[] method(int var1) { if(var1 == ~L.length) //<- this return a(i1, 0, false);
byte[] header = new byte[]{255, 216}; string ascii = Encoding.ASCII.GetString(header); I expect ASCII to
byte[] content = Encoding.UTF8.GetBytes(data); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = POST; request.ContentType = application/json;
byte[] tagData = GetTagBytes(tagID, out tiffDataType, out numberOfComponents); string str = Encoding.ASCII.GetString(tagData); With windows
Given a byte array with a length of two we have two possibilities for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.