CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 16

Threaded View

  1. #1
    Join Date
    May 2005
    Location
    Estonia
    Posts
    235

    [RESOLVED] Adding char to beginning of string

    I have variable that is sometimes like 2 digits, but sometimes it goes to 1 digit, like 0, 1, 2 etc.
    And when it's < 2 then i need to add zero (char) before it so it will look like 01, 02 etc.
    I know strcat can merge strings but it can add strings(chars) only at the end of char. but i need to add to the beginning of string or char.
    Im using Borland C++ 3.1. There is strnset and i can add char with this to beginning but it erases number that i have (1, 2, 3 etc) (almost useless function).
    I made same app in Pascal, there was so easy:
    Code:
    if length(var1) < 2 then var1:='0' + var1
    but C++ don't accept this, so all i need to know how to do this '0' + var1 in C++.
    If somebody knows how to solve this then plz let me know. Im searching in Google also.
    Any hints or tips are welcome.

    thx in advance.
    Last edited by BytePtr; July 4th, 2005 at 05:20 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured