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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:37:12+00:00 2026-06-12T12:37:12+00:00

I have two strings I want to combine and have not exceed a certain

  • 0

I have two strings I want to combine and have not exceed a certain width.

$string = sprintf("%4(%s %s)", $s1, $s2);
//s1 s

Notice how the combined %s %s did not exceed a width of 4.

How can I do this with sprintf?

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-12T12:37:13+00:00Added an answer on June 12, 2026 at 12:37 pm

    You probably need to add more detail to your question – what do you want to happen if the fields are longer than 3 characters (4 – one space)?

    But maybe this is what you want:

    sprintf("%.4s", "$s1 $s2");
    

    That will output the combined string "$s1 $s2", pruned to 4 characters. Of course substr would do the same, this might be useful in the context of a longer format string.

    To be honest I hadn’t realised before that the precision specifier (. followed by number) could be used with %s.

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

Sidebar

Related Questions

In template I have two strings which I want to combine in one. {assign
I have a List<String> and two List<CustomObject> . I want to combine two List<CustomObject>
i have two strings in a php i want to make following checks in
I have two strings in a java program, which I want to mix in
I have two MySQL tables, and I want to find and replace text strings
I have two different arrays, one with strings and another with ints. I want
I have two possible widths for a string i want to display in a
I have two Perl string variables containing date values. I want to check whether
I want to test whether two languages have a string in common. Both of
I have two strings String s1=426F62; String s2=457665; The strings are in hex representation.

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.