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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:51:32+00:00 2026-05-18T03:51:32+00:00

This has got to be simple — surely this method is supposed to work

  • 0

This has got to be simple — surely this method is supposed to work — but I’m having some kind to two-byte-to-one-byte problem, I think.

The purpose of the code is to generate a string of 0 characters of a certain length (10 minus the number of digits that will be tacked onto the end). It looks like this:

const unichar zero = 0x0030;
NSString *zeroBuffer = [NSString stringWithCharacters:&zero length:(10 - [[NSString stringWithFormat:@"%i", photoID] length])];  

Alternate second line (casting the thing at address &zero):

NSString *zeroBuffer = [NSString stringWithCharacters:(unichar *)&zero length:(10 - [[NSString stringWithFormat:@"%i", photoID] length])];

0x0030 is the address of the numeral 0 in the Basic Latin portion of the unicode table.

If photoID is 123 I’d want zeroBuffer to be @”0000000″. What it actually ends up as is a zero and then some crazy unicode characters along the lines of (not sure how this will show) this:

0䪨 燱ܾ뿿﹔

I’m assuming that I’ve got data crossing character boundaries or something. I’ve temporarily rewritten it as a dumb substring thing, but this seems like it would be more efficient.

What am I doing wrong?

  • 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-18T03:51:33+00:00Added an answer on May 18, 2026 at 3:51 am

    stringWithCharacters:length: expects the first argument to be the address of a buffer containing each of the characters to be inserted in the string in sequence. It’s reading your character zero for the first character, then advancing to the following memory address and reading whatever data is there for the next character, and so on. This is not the right method for doing what you’re trying to do.

    Alas, there isn’t a built-in repeat-this-string method. See the answers here for suggestions.

    Alternatively, you can avoid the issue completely and just do this:

    [NSString stringWithFormat:@"%010i", photoID];
    

    That causes the number formatter to output a decimal number padded with ten zeroes.

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

Sidebar

Related Questions

The answer to this has got to be simple, but I sure don't see
This has got to be something simple: I set up a frames page with
Ok, this has got to be a super simple problem. I just can't seem
This has got to be something I just missed, but how do I add
I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on
There has got to be an answer to this, but I am a total
Has anybody got this to actually work? Documentation is non existent on how to
I got some legacy code that has this: <?PHP if(isset($_GET['pagina'])==homepage) { ?> HtmlCode1 <?php
I've got a web service: http://machine001/Services/conversionService.asmx This web service has one method in it
Alright, this one (3a; sample problem with provided answer) has got me scratching my

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.