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

  • SEARCH
  • Home
  • 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 9127773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:21:41+00:00 2026-06-17T07:21:41+00:00

This post might be more theory than code. I was wondering if there is

  • 0

This post might be more theory than code.

I was wondering if there is a (relatively) simple way to use a text table (basically an array of chars) and replace the chars in a string based on their value.

Let me elaborate.

Let’s say we have this two line table:

table[0x0] = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'};
table[0x1] = new char[] {'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ']', ',', '/', '.', '~', '&'};

Each array has 16 members, 0-F in hex.

Say we have a string “hello” converted to hex (68 65 6C 6C 6F). I want to take these hex numbers, and map them to the new locations as defined in the table above.

So, “hello” would now look like this:

07 04 0B 0B 0E

I can easily convert the string into an array, but I am stuck on what to do next. I feel a foreach loop would do the trick, but it’s exact contents I do not yet know.

Is there an easy way to do this? It seems like it shouldn’t be too hard, but I’m not quite sure how to go about doing it.

Thank you very much for any help at all!

  • 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-17T07:21:42+00:00Added an answer on June 17, 2026 at 7:21 am
    static readonly char[] TABLE = {
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
        'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ']', ',', '/', '.', '~', '&',
    };
    
    // Make a lookup dictionary of char => index in the table, for speed.
    static readonly Dictionary<char, int> s_lookup = TABLE.ToDictionary(
                c => c,                          // Key is the char itself.
                c => Array.IndexOf(TABLE, c));   // Value is the index of that char.
    
    static void Main(string[] args) {
    
        // The test input string. Note it has no space.
        string str = "hello,world.";
    
        // For each character in the string, we lookup what its index in the
        // original table was.
        IEnumerable<int> indices = str.Select(c => s_lookup[c]);
    
        // Print those numbers out, first converting them to two-digit hex values,
        // and then joining them with commas in-between.
        Console.WriteLine(String.Join(",", indices.Select(i => i.ToString("X02"))));
    }
    

    Output:

    07,04,0B,0B,0E,1B,16,0E,11,0B,03,1D
    

    Note that if you provide an input character that isn’t in the lookup table, you’re not going to notice it right away! Select returns an IEnumerable, that is lazily-evaluated only when you go to use it. At that point, if the input character is not found, the dictionary [] call will throw an exeception.

    One way to make this more obvious is to call ToArray() after the Select, so you have an array of indices, and not an IEnumerable. This will force the evaluation to happen immediately:

    int[] indices = str.Select(c => s_lookup[c]).ToArray();
    

    Reference:

    • Array.IndexOf
    • Enumerable.ToDictionary
    • Enumerable.Select
    • String.Join
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Caveat : I'm not sure if this post might be better suited for SuperUser
I want to refer to this post, because it might relate: Make Form Fields
This is a more a philosophical question about Apple's design decisions than a question
This post is not really about the bug in the code down below, I
Sorry, this might be duplicated, I'm not sure if my previous attempt to post
This blog post suggests that it might be possible to play YouTube videos with
EDIT To make this post a bit more constructive, and let it possibly help
Excuse the title of this post, but I can't really think of a more
This post shows how to axiomatise a length function for Z3's built-in lists. However,
This post on SO answers most of the questions I have (much thanks to

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.