Click here to Skip to main content
15,843,031 members
Home / Discussions / C#
   

C#

 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 10:59
professionalMember 105306516-Jan-17 10:59 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
OriginalGriff6-Jan-17 11:40
mveOriginalGriff6-Jan-17 11:40 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 11:49
professionalMember 105306516-Jan-17 11:49 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Dave Kreskowiak6-Jan-17 12:15
mveDave Kreskowiak6-Jan-17 12:15 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 12:29
professionalMember 105306516-Jan-17 12:29 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Dave Kreskowiak6-Jan-17 12:33
mveDave Kreskowiak6-Jan-17 12:33 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 12:37
professionalMember 105306516-Jan-17 12:37 
QuestionC# Get random object form JSON File Pin
Pavlex44-Jan-17 8:22
Pavlex44-Jan-17 8:22 
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:
C#
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())
                {
                    //A
                    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;
                    //B
                    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;
                    //C
                    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;
                    //D
                    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:

C#
[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; }
        }

AnswerRe: C# Get random object form JSON File Pin
NotPolitcallyCorrect4-Jan-17 8:41
NotPolitcallyCorrect4-Jan-17 8:41 
GeneralRe: C# Get random object form JSON File Pin
Gerry Schmitz4-Jan-17 8:59
mveGerry Schmitz4-Jan-17 8:59 
GeneralRe: C# Get random object form JSON File Pin
NotPolitcallyCorrect4-Jan-17 9:32
NotPolitcallyCorrect4-Jan-17 9:32 
GeneralRe: C# Get random object form JSON File Pin
OriginalGriff4-Jan-17 9:11
mveOriginalGriff4-Jan-17 9:11 
GeneralRe: C# Get random object form JSON File Pin
NotPolitcallyCorrect4-Jan-17 9:27
NotPolitcallyCorrect4-Jan-17 9:27 
QuestionA Better Way? Pin
Kevin Marois4-Jan-17 6:35
professionalKevin Marois4-Jan-17 6:35 
AnswerRe: A Better Way? Pin
Eddy Vluggen4-Jan-17 8:06
professionalEddy Vluggen4-Jan-17 8:06 
AnswerRe: A Better Way? Pin
Jon McKee4-Jan-17 11:00
professionalJon McKee4-Jan-17 11:00 
AnswerRe: A Better Way? Pin
Pete O'Hanlon4-Jan-17 21:46
subeditorPete O'Hanlon4-Jan-17 21:46 
GeneralRe: A Better Way? Pin
Kevin Marois5-Jan-17 5:32
professionalKevin Marois5-Jan-17 5:32 
GeneralRe: A Better Way? Pin
Eddy Vluggen5-Jan-17 5:36
professionalEddy Vluggen5-Jan-17 5:36 
GeneralRe: A Better Way? Pin
Pete O'Hanlon5-Jan-17 7:00
subeditorPete O'Hanlon5-Jan-17 7:00 
AnswerRe: A Better Way? Pin
#realJSOP6-Jan-17 5:45
mve#realJSOP6-Jan-17 5:45 
GeneralRe: A Better Way? Pin
Kevin Marois6-Jan-17 5:47
professionalKevin Marois6-Jan-17 5:47 
QuestionC#.net:Listen to event fire on app minimize to tray Pin
hassaan mustafa4-Jan-17 4:07
hassaan mustafa4-Jan-17 4:07 
AnswerRe: C#.net:Listen to event fire on app minimize to tray Pin
Eddy Vluggen4-Jan-17 8:05
professionalEddy Vluggen4-Jan-17 8:05 
QuestionInteracting with a Page Web Service (OData v4) Error Pin
MaWeRic3-Jan-17 23:03
MaWeRic3-Jan-17 23:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.