|
Thank you
that's what I want
|
|
|
|
|
See how much easier if it's when you ask the right question?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Just a question how to change a number like 45.5 to 45.50 in TD
|
|
|
|
|
That's where it starts to get complicated, because now you need more than a "simple" text processor - which is all a regex is.
The way I'd probably do it is not to use a regex but feed the whole page into an HTML processor and start working with the data from there.
What exactly are you trying to achieve? Because there may be better way of doing it than the deconstruction you seem to be doing so far.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I want to convert all the numbers in this schéma
input
<TD>25.5</TD>
<TD>45.6</TD>
<TD>19</TD>
<TD>25</TD>
output
<TD>25.50</TD>
<TD>45.60</TD>
<TD>19.00</TD>
<TD>25.00</TD>
|
|
|
|
|
OK, so what's generating this table? Is it code you wrote or is this some kind of web page scraping you're doing?
|
|
|
|
|
the code is some kind of web page scraping
|
|
|
|
|
I would suggest you start using the HTML Agility Pack to make scraping a bit easier, but that's up to you.
It seems you're trying to treat the page as a large string an manipulate it as such. Instead of doing that, you might want to just grab the actual data, not the tags around them, store them as appropriate in your application data model, and then you can format the data any way you want when you present it back to the user in whatever application you're writing.
|
|
|
|
|
|
How to get random strings from JSON Object? For example when first time program is run on when I click on button a1 button1.Text should be "SUVO",when click on button b3 button8.Text should be "TRIJUMFALNA KAPIJA" and so on...
[ { "a1": "SUVO", "a2": "SLATKO", "a3": "BELO", "a4": "ISTINA", "a5": [ "vino" ], "b1": "LOVOR", "b2": "POSTOLJE", "b3": "TRIJUMFALNA KAPIJA", "b4": "DAN", "b5": [ "pobeda", "pobede", "pobjeda" ], "c1": "UEFA", "c2": "TAKMIČENJE", "c3": "ELIMINACIJA", "c4": "ŠAMPIONA", "c5": [ "kup" ], "d1": "ISUS", "d2": "KRV", "d3": "VITEZOVI", "d4": "OKRUGLI STO", "d5": [ "sveti gral", "svijeti gral", "svjeti gral", "gral" ], "rr": [ "pehar", "pjehar" ] } ]
When clicked button that is called "new game" buttons should have this text: And now when clicked on button a1 button1.Text now should be "hudini",when click on button b3 button8.Text should now be "zid" and so on...
{ "a1": "hudini", "a2": "trik", "a3": "plašt", "a4": "predstava", "a5": [ "mađioničar", "madjionicar", "čarobnjak", "carobnjak", "madjioničar" ], "b1": "svila", "b2": "bicikl", "b3": "zid", "b4": "država", "b5": [ "kina" ], "c1": "kornet", "c2": "frikom", "c3": "delta", "c4": "kugla", "c5": [ "sladoled" ], "d1": "školjka", "d2": "aparat", "d3": "sluh", "d4": "bubanj", "d5": [ "uši", "uvo", "usi", "uho" ], "rr": [ "štapić", "stapic", "štap", "stap" ] },
Source code of program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<MyModel> data;
private void Form1_Load(object sender, EventArgs e)
{
data = GetJsonFromFile(@"MyData.json");
}
private List<MyModel> GetJsonFromFile(string path)
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(File.ReadAllText(path))))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<MyModel>));
List<MyModel> data = (List<MyModel>)serializer.ReadObject(stream);
return data;
}
}
private void button_Click(object sender, EventArgs e)
{
CustomMessage frm = new CustomMessage();
frm.ShowDialog();
MyModel model = data[0];
Button btn = sender as Button;
switch (btn.Text.ToString())
{
case "A":
List<string> A = model.a5;
button5.Text = A[0];
break;
case "A1":
string A1 = model.a1;
button1.Text = A1;
break;
case "A2":
string A2 = model.a2;
button2.Text = A2;
break;
case "A3":
string A3 = model.a3;
button3.Text = A3;
break;
case "A4":
string A4 = model.a4;
button4.Text = A4;
break;
case "B":
List<string> B = model.b5;
button12.Text = B[0];
break;
case "B1":
string B1 = model.b1;
button13.Text = B1;
break;
case "B2":
string B2 = model.b2;
button14.Text = B2;
break;
case "B3":
string B3 = model.b3;
button15.Text = B3;
break;
case "B4":
string B4 = model.b4;
button16.Text = B4;
break;
case "C":
List<string> C = model.c5;
button17.Text = C[0];
break;
case "C1":
string C1 = model.c1;
button18.Text = C1;
break;
case "C2":
string C2 = model.c2;
button19.Text = C2;
break;
case "C3":
string C3 = model.c3;
button20.Text = C3;
break;
case "C4":
string C4 = model.c4;
button21.Text = C4;
break;
case "D":
List<string> D = model.d5;
button7.Text = D[0];
break;
case "D1":
string D1 = model.d1;
button8.Text = D1;
break;
case "D2":
string D2 = model.d2;
button9.Text = D2;
break;
case "D3":
string D3 = model.d3;
button10.Text = D3;
break;
case "D4":
string D4 = model.d4;
button11.Text = D4;
break;
case "???":
List<string> RR = model.rr;
button6.Text = RR[0];
break;
}
}
MyModel Class:
[DataContract]
public class MyModel
{
[DataMember]
public string a1 { get; set; }
[DataMember]
public string a2 { get; set; }
[DataMember]
public string a3 { get; set; }
[DataMember]
public string a4 { get; set; }
[DataMember]
public List<string> a5 { get; set; }
[DataMember]
public string b1 { get; set; }
[DataMember]
public string b2 { get; set; }
[DataMember]
public string b3 { get; set; }
[DataMember]
public string b4 { get; set; }
[DataMember]
public List<string> b5 { get; set; }
[DataMember]
public string c1 { get; set; }
[DataMember]
public string c2 { get; set; }
[DataMember]
public string c3 { get; set; }
[DataMember]
public string c4 { get; set; }
[DataMember]
public List<string> c5 { get; set; }
[DataMember]
public string d1 { get; set; }
[DataMember]
public string d2 { get; set; }
[DataMember]
public string d3 { get; set; }
[DataMember]
public string d4 { get; set; }
[DataMember]
public List<string> d5 { get; set; }
[DataMember]
public List<string> rr { get; set; }
}
|
|
|
|
|
Pavlex4 wrote: How to get random strings
You use the Random class to generate a random number and pull that index from whatever string collection you have.
Pavlex4 wrote: btn.Text.ToString()
Every time I see this I wonder about it and every time I ask, I don't get an answer. Maybe you can tell me what benefit is it that you think you get from converting a string to a string?
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
It's like the "Learner Driver" notice affixed to the rear of a vehicle.
Until they actually learn to remove it, we can only assume.
|
|
|
|
|
Gerry Schmitz wrote: "Learner Driver"
Yes, I believe you are correct sir.
It amazes me that how some people call themselves developers nowadays that don't have any idea how computers work, what a file is, what a path is, what a directory is, etc.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
Check out his other questions and you'll find he doesn't know, and doesn't appear to be trying to learn anything. At a guess, he has conned his way into a job he has no idea how to do, and is trying to use Google and us to keep him getting paid.
A help vampire, in fact.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: A help vampire
Indeed. One of the reasons I asked was to see if he actually had a rational explanation. I expect not.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
I'm trying to handle the case where the client calls through the hub into the server and an error occurs.
If an error occurs then there could be an inner exception. So far I have this but it feels funny. Anyone have a better way?
_hubProxy.Invoke("SomeMethodName", model).ContinueWith((t) =>
{
if (t.Exception != null && t.Exception.InnerException != null)
{
throw t.Exception.InnerException;
}
});
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The inner exception may have an inner exception, and so on. Instead of throwing the inner exception, I'd throw the outer one, as it would (should) contain all inner-exceptions.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Since Task.Exception is an AggregateException you've gotta worry about multiple inner exceptions in addition to the current exception the AggregateException represents unless you know precisely how many exceptions can be thrown. My ideas:
Log current exception, flatten (in the case of nested AggregateExceptions ), and re-throw:
_hubProxy.Invoke("SomeMethodName", model).ContinueWith((t) =>
{
if (t.Exception != null && t.Exception.InnerException != null)
{
throw t.Exception.Flatten();
}
});
Handle exceptions you know how to handle, re-throw the rest:
_hubProxy.Invoke("SomeMethodName", model).ContinueWith((t) =>
{
if (t.Exception != null && t.Exception.InnerException != null)
{
AggregateException ae = t.Exception.Flatten();
ae.Handle(x =>
{
if (x is IndexOutOfRangeException)
{
return true;
}
return false;
});
}
});
You can avoid Flatten() if you're absolutely sure there are no tasks inside your task. Also the reason I used Handle() is because it conveniently re-wraps all exceptions that did not return true (not handled) in an AggregateException and re-throws them. If you can handle everything or are sure of exactly what exceptions can be thrown you could iterate over the AggregateException.InnerExceptions collection instead and re-throw as you desire.
EDIT: Quick addendum: If you're using C#6 you can simply the if-statement to:
if (t.Exception?.InnerException != null)
Looks cleaner to me but to each their own 
modified 4-Jan-17 21:37pm.
|
|
|
|
|
This is why I am no longer interested in helping him. If he showed even a touch of progression or having learned a lesson, I would still help out.
This space for rent
|
|
|
|
|
I don't understand this response to my question
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I'm guessing it should have been part of the thread above
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It should - my connection to CP was doing all sorts of funny things this morning. Your questions I'm fine with. It's the help vampire above that I am not interested in helping any more.
This space for rent
|
|
|
|
|
I posted this tip that tries to see if an exception in the chain is of a particular type. You could use the code as a basis for bending it to your will.
Find your inner exception
(I don't know what's going on with link pasting.)
".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
|
|
|
|
|