|
If i have this number: 100000000000
my code will read it like this:
if (rol > 99999999999) label1.Text = get3digit(rol) + " miliarde";
...
int get3digit(Int64 myVal)
{
char mg1 = myVal.ToString()[0];
char mg2 = myVal.ToString()[1];
char mg3 = myVal.ToString()[2];
char[] chars = { mg1, mg2, mg3 };
string mg = new string(chars);
int i = int.Parse(mg);
return i;
}
999999999999 (it means 999 miliarde) and is the Maximum value i will make the code.
Now, I want to split this number by 3 LAST characters !!!
So it will look like this in the end: "100 000 000 000" (yes, with spaces)
Also for other LESS numbers than this one.
100 000 000 000
10 000 000 000
1 000 000 000
100 000 000
10 000 000
1 000 000
100 000
10 000
1 000
and this is the last value to insert the space. So 9 cases. I give multiple of 10 example here to be easy to understand, but it will be other numbers between 0 and 999 milliard.
My idea is to use -char- as i did already, to separate the last numbers.
But... maybe there is some funky way of doing it more easily?
Or AUTOMATIC/ Default way?
Thank you very much.
|
|
|
|
|
Int64 i = 100000000;
Console.WriteLine( i.ToString( "### ### ###" ).TrimStart() );
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
EXCELENT !!! Thank you very much.
|
|
|
|
|
Hi,
you can specify how a number gets formatted on output without performing any char or string manipulation yourself.
The basic mechanism consists of calling the ToString() method while providing a format pattern as well as an object of type NumberFormatInfo that holds your specific wishes. In this case it would be:
NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
nfi.NumberGroupSeparator = " ";
int yourNumber=123456789;
string yourFormattedNumber = yourNumber.ToString("#,0", nfi);
Obviously you need to create nfi only once, you can reuse it as often as you want.
|
|
|
|
|
This will work regardless of the type of number, and regardless of its value.
long number = 100000000000;
string value = string.Format("{0:#,##0}", number).Replace(",", " ");
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 18-Apr-19 8:26am.
|
|
|
|
|
public string HowManyMillion(int millions, string suffix) => $"{millions / 1000000} {suffix}";
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I want to apply username n password when calling wcf from client. I don't know how to create certificate.when i run command in cmd it shows makecert is not registered. I am using wshttpbinding with security mode transport and presidential type basic.how can i solve my issue.pls help me
|
|
|
|
|
wcf passing credentials with https transport - Google Search[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm working on a small project and trying to familiarize myself with C# to boot (perhaps in a ham-fisted way).
The program dynamically creates an array of buttons and uses an imagelist to place an image on the button (not the button background). Clicking on the button increments which image is displayed on the buttons.
The issue I have is that I wish to save in a text file the current image index of the image - so it can be reloaded in future. Whilst I can reference and change certain things like text and background image - I cannot work out a way to access the index of the image currently in-use.
I appreciate I've provided only a little info, if more it required I will do my best to answer.
|
|
|
|
|
For anyone searching that may come across this it was a newbie not fully understanding casting.
I was hoping this was correct:
this.tabControl_Schedules.TabPages[tabpage_counter].Controls["button" + announcement_counter++].ImageIndex = 1;
Where instead I needed to do something like:
Button butt = new Button();
butt = (Button)this.tabControl_Schedules.TabPages[tabpage_counter].Controls["button" + announcement_counter++];
and..
butt.ImageIndex = 1;
|
|
|
|
|
Member 14271084 wrote:
Button butt = new Button();
butt = ...
You're creating a new instance of a class, only to throw it away on the following line. The only effect that will have is to increase the memory usage and "GC churn" for your application.
You should remove the new Button() allocation. You can either declare the variable without initializing it, or combine the declaration with the assignment from the following line.
Button butt;
butt = (Button)this.tabControl_Schedules.TabPages[tabpage_counter].Controls["button" + announcement_counter++];
Button butt = (Button)this.tabControl_Schedules.TabPages[tabpage_counter].Controls["button" + announcement_counter++];
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Since you create the Buttons at run-time, why not keep track of them and their current index as you create them ? You can then serialize them.
public Dictionary<string, Button> BtnDict = new Dictionary<string, Button>();
public void AddNewButton(ImageList btnimagelist, Control btnsite, string btntext, int btnimgindex, Point btnlocation)
{
Button btn = new Button
{
Text = btntext,
ImageList = btnimagelist,
ImageIndex = btnimgindex,
Location = btnlocation
};
btnsite.Controls.Add(btn);
}
public void IncBtnImage(string btntext)
{
Button btn = BtnDict[btntext];
int icnt = btn.ImageList.Images.Count;
int ndx = ++btn.ImageIndex;
if (ndx == icnt) ndx = 0;
btn.ImageIndex = ndx;
} Do all of these run-time created Buttons use the same ImageList, or does each one have its own ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 17-Apr-19 3:00am.
|
|
|
|
|
I'm not at all sure that I understand why you are having problems accessing the image index - it's held in a property that you modify in order to change the image that is displayed from the ImageList.
And if you can access it to change it when the button is clicked, why can't you access the ImageIndex property of the button when you want to save it?
This is why "working on a small project and trying to familiarize myself with C# to boot" is a bad idea: you don't know what you are missing that could make your life a whole load easier! I'd strongly recommend that you go on a course, or get a book - trying to "pick it up as you go along" is not a viable strategy any more than trying to learn to drive by entering an F1 race ...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am trying to serialize json using an object and have it be in the format below. Please provide any info as my object will not parse like this. Thanks.
{"custom-fields": {"post-date":"2019-04-10" }}
My code using an object produces value pairs and has trouble with double quotes if I try to use a string variable to build out the json.
|
|
|
|
|
In JSON, property names must adhere broadly to javascript variable name guidelines:
Property names must conform to the following guidelines:
Property names should be meaningful names with defined semantics.
Property names must be camel-cased, ascii strings.
The first character must be a letter, an underscore (_) or a dollar sign ($).
Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.
Reserved JavaScript keywords should be avoided (A list of reserved JavaScript keywords can be found below).
Specifically, '-' is not a permitted character in property names, so your JSON cannot be parsed into "legal" objects.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That's interesting, I'd not heard that. And is it the case? The link appears to be a style guide which is always a guide to how somebody else thinks things should be done.
I've always liked this little page : JSON. Whether it's official or not I'm not sure but its succinct, saying that the key is a string and more or less that a string is anything unicode.
So I'd be surprised if the json parser/serialiser rejects the key because of that, even it were the defacto standard.
Regards,
Rob Philpott.
|
|
|
|
|
If you're using JSON.NET[^], you can use the JsonProperty attribute[^] to control the property names. For example:
public class IsoDateTimeFormatConverter : IsoDateTimeConverter
{
public IsoDateTimeFormatConverter(string format)
{
DateTimeFormat = format;
}
}
public class CustomFields
{
[JsonProperty("post-date")]
[JsonConverter(typeof(IsoDateTimeFormatConverter), "yyyy-MM-dd")]
public DateTimeOffset PostDate { get; set; }
}
public class Root
{
[JsonProperty("custom-fields")]
public CustomFields CustomFields { get; } = new CustomFields();
}
...
var x = new Root
{
CustomFields =
{
PostDate = DateTime.Today
}
};
string json = JsonConvert.SerializeObject(x);
If the custom fields are dynamic, then you could use a dictionary:
public class Root
{
[JsonProperty("custom-fields")]
public Dictionary<string, object> CustomFields { get; } = new Dictionary<string, object>();
}
...
var x = new Root
{
CustomFields =
{
["post-date"] = DateTime.Today.ToString("yyyy-MM-dd")
}
};
string json = JsonConvert.SerializeObject(x);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for the reply. This has helped but now I am not getting any data returned to the screen. I have all of the classes in a class called Parm. I called var x = Parm.root {...} There is not a build error but I get "Myproj.Parms.Root press any key to continue" I am trying to use console.writeline(x) to see what is produced. Any ideas?
|
|
|
|
|
Try:
Console.WriteLine(JsonConvert.SerializeObject(x));
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I want to fill between two spline curves with two different colors (Above one of the curves (Red), and
below it (yellow)). And also i want the end user to be able fill the mentioned area with a selected pattern. how can i do that?
i have used from ValueToPixelPosition but it is not a proper way or i can not do it inpecable.
thanks in advance.
|
|
|
|
|
How do you "fill a curve"? There are "strokes" and stroke thickness and color. There are "shapes" one can "fill". There are "brushes" that can paint a pattern (WPF). You need to identify some primitives to work with. A "pixel", in this case, is a little too primitive.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
You must collect information sufficient to define the spline.
You must determine the intersection points if any. From here I will proceed with the assumption that there are two and only two intersecting points.
You must then determine the 'area' represented by the intersection.
The user can then point to an area
Determine if the area is in the is within the intersection. The points and the curves define this.
Then allow the user to pick a pattern and color.
Then use the last two steps to fill in the area.
You start at one end and color to the other. You will need to figure out how to chop the pattern when you reach the edge.
|
|
|
|
|
You should make polygons, closed curves, paths, or some other graphic object to represent the areas that you want to fill. Then you can use the Graphics object's FillXxx methods to fill the areas with whatever brushes you like.
Exactly how you define the closed areas will depend on exactly what you want. If you post a sketch, that would help.
|
|
|
|
|
I this what VOIP is? If so, do you need a provider to do VOIP? Can I roll my own? An example would be nice.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|