Discussion:
How can I write a short code to accomplich this
(too old to reply)
Tony Johansson
2016-11-29 18:01:00 UTC
Permalink
Hello!

This is pseducode
Note n can be any number from 0 to 99.

If the string n = 0 then
string result = ">000:0"

If the string n = 3 then
string result = ">300:0"

If the string n = 27 then
string result = ">270:0"

I can solve this by using normal if clause and contenate but I hope someone
have a better shorter solution

//Tony
Tony Johansson
2016-11-29 19:58:40 UTC
Permalink
Post by Tony Johansson
Hello!
This is pseducode
Note n can be any number from 0 to 99.
If the string n = 0 then
string result = ">000:0"
If the string n = 3 then
string result = ">300:0"
If the string n = 27 then
string result = ">270:0"
I can solve this by using normal if clause and contenate but I hope
someone have a better shorter solution
//Tony
int value = 27;
string s = String.Format("0:{0:000}>", value);
char[] charArray = s.ToCharArray();
Array.Reverse(charArray);
string foo = new string(charArray);
bradbury9
2016-11-29 20:39:35 UTC
Permalink
Post by Tony Johansson
Post by Tony Johansson
Hello!
This is pseducode
Note n can be any number from 0 to 99.
If the string n = 0 then
string result = ">000:0"
If the string n = 3 then
string result = ">300:0" + ":0";
If the string n = 27 then
string result = ">270:0"
I can solve this by using normal if clause and contenate but I hope
someone have a better shorter solution
//Tony
int value = 27;
string s = String.Format("0:{0:000}>", value);
char[] charArray = s.ToCharArray();
Array.Reverse(charArray);
string foo = new string(charArray);
int value = 3;
string result = ">" + value.ToString().PadRight('0',3) + ":0";
Arne Vajhøj
2016-11-30 00:31:27 UTC
Permalink
Post by Tony Johansson
This is pseducode
Note n can be any number from 0 to 99.
If the string n = 0 then
string result = ">000:0"
If the string n = 3 then
string result = ">300:0"
If the string n = 27 then
string result = ">270:0"
I can solve this by using normal if clause and contenate but I hope
someone have a better shorter solution
Maybe:

public static string XLate(int v)
{
return (v < 10) ? string.Format(">{0}00:0", v) :
string.Format(">{0}0:0", v);
}

Arne

Loading...