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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:39:56+00:00 2026-05-27T00:39:56+00:00

Say I have a string phone = 1-800-test I need to convert the letters

  • 0

Say I have a string phone = "1-800-test"

I need to convert the letters to numbers.

Doing something like this doesn’t work (note I’m looping it of course):

phone = phone.replace(phone.charAt(9), (char) getNumber(phone.charAt(9)));

Note that getNumber() is a method that takes a letter and returns a number:

int getNumber(char uppercaseLetter)

Anyway, I get some weird output with the letter replaced by a weird square.

How should I replace the letters with numbers?

  • 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-05-27T00:39:56+00:00Added an answer on May 27, 2026 at 12:39 am

    Doing (char)1 gives you the ASCII character represented by 1 so you get the weird square.
    You can just use ‘1’ to instead. If you insist on converting integers to ASCII, just add 48 (since that is where the digits start in the ascii). i.e. (char)48 is ‘0’, (char)49 is ‘1’ and so on. That doesn’t seem necessary for me though.

    The exact answer to your question, is use:

    phone = phone.replace(phone.charAt(9), (char)(48+getNumber(phone.charAt(9))));
    

    But it is NOT recommended…

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

Sidebar

Related Questions

Say I have the string 1,2,3,4,5 and I want to convert this to an
So say I have a string like so of a path $path = '/path/to/../../up/something.txt';
Lets say I have string like this, String sample = This is a sample
say I have a string like so Testing How could I have it remove
Say i have a string that i need to evaluate in javascript such as
Say I have a string: the quick brown fox jumped over the moon.this text
Lets say a have a string such as this one: string txt = Lore
Let's say I have String Table that have a few strings (like mother, father,
For example, say I have string like: duck duck duck duck goose goose goose
Lets say I have a Phone number my classes need to validate and keep

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.