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 7775539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:39:26+00:00 2026-06-01T17:39:26+00:00

What is the fastest way to convert a String into an array of Short

  • 0

What is the fastest way to convert a String into an array of Short integers representing the character codes?

I am now using this but it can probably be much faster:

Dim shortsarray(mystring.Length - 1) as Short
For i As Integer = 0 To mystring.Length - 1
  shortsarray(i) = AscW(mystring.Chars(i))
Next

Thanks.

  • 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-01T17:39:27+00:00Added an answer on June 1, 2026 at 5:39 pm
    Dim shortsarray(mystring.Length - 1) as Short //One calculation
    For i As Integer = 0 To mystring.Length - 1   //One calculation, repeats n times
      shortsarray(i) = AscW(mystring.Chars(i))    //Three calculations, repeats n times
    Next
    

    As a result, this should run in O(3n+1), or O(n). This is linear on the length of the input, and there isn’t much improvement you can expect from that since you’re doing a character-wise conversion. I think this is probably as good as you can expect, though there may be a library that will just convert the whole word in one go, making your code cleaner.

    If you need performance increases, you want to first profile your whole program. This snippet may not be the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP, what's the fastest way to convert a string like this: 123 to
What is the fastest way to convert this string to this array? $string =
What's the fastest way to turn a string into a byte[] array in C#?
What is the fastest/easiest way to convert an array (of double) into a MFC-Bitmap
I need fastest way to convert byte array to short array of audio data.
What's the fastest way using either DOS scripting or PowerShell to run this simple
What is the fastest way to compare a string with an array of strings
Let's say I have a Dictionary<String, Guid> What is the fastest way to convert
What's the fastest way to convert a string represented by (const char*, size_t) to
What is the fastest way to convert a simple array to an associative array

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.