Click here to Skip to main content
15,354,717 members

Comments by Lupu5R3x (Top 13 by date)

Lupu5R3x 2-Apr-20 2:17am View
That's what I did, some one told me that I could past my json as C# classes, and that save almost the same result as Afzaal's.

Lupu5R3x 31-Mar-20 9:33am View
Afzaal's answer pointed me in the right direction, though it needed some more to work, but sins I did paste the wrong Json, my guess is that Afzaal would had thrown the right answer, so I accept his solution.
I have added the code that works below.
Lupu5R3x 30-Mar-20 7:45am View
Hi Afzaal
I got an error using this: public class JsonObjectHolder {
public string Updates { get; set; }
public Dictionary<int, mydata=""> { get; set; }
But fixed it by adding a name to the Dictionary prop, public Dictionary<int, mydata=""> Dict { get; set; }

But I cant get in contact with the dictionary, I tried:
var jsonTest = JsonConvert.DeserializeObject<jsonobjectholder>(serverResponseJsonString.Result);


foreach (KeyValuePair<int, updateslist=""> item in jsonTest.Dict)
But I get an Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at " Console.WriteLine(jsonTest.Dict.Count);", and I out comment that and tries my foreach loop I get the same error.

What Am i doing wrong?

Lupu5R3x 29-Mar-20 9:25am View
Hi I have.
When sending json I use using var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
With normal post I use using (FormUrlEncodedContent content = new FormUrlEncodedContent(values)).
But it also works with StringContent and "application/x-www-form-urlencoded".

But it seems that what I want is impossible both from the server side and from the client side.

So I just send my json a post, either in urlform or as string - both seems to work.

Lupu5R3x 28-Mar-20 18:05pm View
Hi No the post only holds the token, and the json holds the guid and versions og my program and dll's
Lupu5R3x 29-Feb-20 10:43am View
In my form code I do call ShowDialog (maybe I should had added that information :()

In my form code I have internal new MsgBoxResult Show()
return Result;
Lupu5R3x 25-Feb-20 10:58am View
That's why I asked my question, to learn how to use the code, If I don't ask I don't learn, though most often I can find the answer to my questions using google, and that's the way I prefer to it, I hate to ask questions - course that means that I failed to find the answer on my own :(.

All I current have is a simple WinForm, that looks like a messagebox.
It's build over code examples found by googleing, I could had created it from scratch, but I saw no reason to recreate the wheel :).

My problem, is/was that that if I double clicked the label I use to display the message, the message is copied to the clipboard, and I wanted to prevent that.

Lupu5R3x 25-Feb-20 10:46am View
I figured it out, I just added the code to the design code, and changed my label to SingleClickLabel.

Though, I would had preferred to add it to the Toolbox, so I could use it in other projects without copying the code to the designer, but I guess I figure out how to that at some point in the future.

Lupu5R3x 24-Feb-20 15:19pm View
Sry, C# is new to me.
I don't understand, you answer :(.
I have added the class to my project form code (not design code).

Lupu5R3x 5-Feb-20 12:47pm View
\K "Resets start of match at the current point in subject string. Note that groups already captured are left alone and still populate the returned array; it is therefore always possible to backreference to them later on. Action of \K is similar but not identical to a look-behind, in that \K can work on alternations of varying lengths."

So this regreplace".{1,60}\K(\s{1,2}|$)", "\r\n"
which returned one string "splitted" by 60 char in one string at once, ended up as this.
string splitPattern = @"(.{1,60})(\s{1,2}|$)";
RegexOptions regexOptions = RegexOptions.IgnoreCase;
Regex splitText = new Regex(splitPattern, regexOptions);
StringBuilder result = new StringBuilder();

foreach (Match match in splitText.Matches(input))
if (match.Success)
result.Append(match.Groups[0].Value + "\r\n");
return result.ToString();

Lupu5R3x 5-Feb-20 12:17pm View
Hmm, yes it seems that it would be the most simple solution to my problem. :)

Regardless of how annoying it is that all my one line regex's end up as several lines in C# to get the same result :( the last regex I translated went from one line to 10 lines in C# :O course C# don't support \K :'(

Lupu5R3x 5-Feb-20 11:43am View
Hi I tried that, but [1] just give me the name of the first group name in my pattern, not the name of the captured group.

eg. if I have this pattern (?(abc)|(?<d>def)|(?<g>ghi) and test string def [1] just gives me a :(

Lupu5R3x 5-Feb-20 11:23am View
I'm trying to convert a Autoit regex pattern like this "(abc)|(def)|(ghi)", 1
Where ,1 returns a match of arrays.

So the result of "def" would return [0] = , [1] = def

But sins I couldn't find any equitant to match of arrays in C#, my hope was that I could use naming groups to return the name of the group that was matched.

eg. (?abc)|(?<d>def)|(?<g>ghi) and test def should (was my thought) return d.

But when trying what @OriginalGriff sugested, I just get the group name I specified so [1] returns a, [2] = b but that it does regardless of what the match is.

And yes I should have specified exactly what I was trying to achieve, with the regex, sry for that :(