473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Equivalent String formats in CSharp

L
Hi there,

Something like this in C++

String sTmp;
for (int i = 5; i <=15; i++)
{
sTmp.format("%2s", i)
}

would print

5
6
7
8
9
10
11
12
12
14
15

I should imitate the same in Csharp. ( Notice the space before the
numbers 5 through 9). Is there a way to do this using String.Format in
Csharp?

Thanks,
Lalasa.

Nov 16 '05 #1
2 1648
string sTmp;
for (int i = 5; i <=15; i++)
{
sTmp = String.Format("{0,2}", i);
}
the values inside the {}s are: the index into the parameters following the
format string, comma, the width of the field it should be placed in (the
width is optional). This can (optionally) also be follwed by a colon and a
format specifier.
"L" <la********@investors.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi there,

Something like this in C++

String sTmp;
for (int i = 5; i <=15; i++)
{
sTmp.format("%2s", i)
}

would print

5
6
7
8
9
10
11
12
12
14
15

I should imitate the same in Csharp. ( Notice the space before the
numbers 5 through 9). Is there a way to do this using String.Format in
Csharp?

Thanks,
Lalasa.

Nov 16 '05 #2
L
Thanks a lot.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Speranza | last post by:
Does anyone know what the C# equivalent of the shell command is? I want to play an mp3 file using the users default player. Regards, Paul Speranza
3
by: Bob Maggio | last post by:
I have created a function that returns a string containing raw HTML to be used on a web form (see below): private string GetReportHTML() { string strHTML = ""; // I have some code here that...
4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
11
by: Miki Watts | last post by:
I'm having a problem with encoding a string... here's my code: byte s = System.Text.Encoding.ASCII.GetBytes(FieldContent); Now, this works fine, as long as there are no bytes that are over 128,...
7
by: Brian Mitchell | last post by:
Is there an easy way to pull a date/time stamp from a string? The DateTime stamp is located in different parts of each string and the DateTime stamp could be in different formats (mm/dd/yy or...
6
by: SevDer | last post by:
Is there a way to test guid string? I want to do it without try catch block to save on performance. Thanks in advance. -- SevDer
2
by: jblankenburg | last post by:
Please help! I am hunting high and low for an equivalent function for MSSQL's DATENAME function. Here's the spec on the function from MSSQL's Books Online: DATENAME Returns a character...
9
by: Kimelia Schiles | last post by:
Hi, I am new to C#, and I am a VB programmer. I would like to know whether there is any function in C# that can is similar to IsNumeric in VB?
2
by: Diego Armando Maradona | last post by:
Hi, I am using toshiba tec sx8 thermal printer for printing our labels, in My old Delphi application I was using such code; ShellExecute(0,'open',Data.cmdbuffer, PChar('/c copy...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.