Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Hughmoris
Apr 21, 2007
Let's go to the abyss!
Here is a very vague question... How is C# for text parsing and regex expressons? I'm a non-programmer trying to help out at work, and we have a 60,000-line data log that I'd like to write a tool for and distribute to my coworkers. They'd input a user ID, and the program would parse the log pulling out relevant information. I'm a Python rookie and I think I could accomplish it in Python but I'd like to learn a language that is easily distributed in the Windows environment.

Hughmoris fucked around with this message at 01:47 on Feb 28, 2015

Adbot
ADBOT LOVES YOU

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Jewel posted:

Incredibly good. Python and C# are my two favorite languages because they both feel just as flexible as eachother out of the box (C# has the wonderful enumeration library and generally a lot of helper libraries/functions) and I use C# primarily now for the same reason you just said, it's easily distributed. Also typed languages are so much nicer than untyped at this point, not to mention the intellisense is great and the compiler errors are helpful.

Thanks, that's good to hear.

Ithaqua posted:

It's fine, but PowerShell might be more up your alley as a non-programmer. PowerShell has regex operators built right in.

http://www.powershelladmin.com/wiki/Powershell_regular_expressions

I don't know a ton about powershell but would there be an issue deploying powershell scripts on Windows XP computers? Or would I have to do some tinkering to get it to work?

Hughmoris
Apr 21, 2007
Let's go to the abyss!
For performance on a script that parses a 60,000+ line text file, does it really matter what method I use to read in the file and iterate over each line? Poking around C# tonight and it looks like there are quite a few different ways to read in files. Is there a standard method I should be using to read and write files, excluding special cases?

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Is there a simple way to iterate through regex matches in C#?

For instance, if I have a string: "Test string 123 and another 456 and a third 789"
And I want to capture any three digits that are together, I think my regex pattern would be "(\\d\\d\\d)"

I'd like to regex the test string and have an output of:

123
456
789

The little snippets I can find online seem overly complicated for iterating through matches.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Scaramouche posted:

I don't have an IDE in front of me, but isn't matches just a collection? So something like
code:
Dim strFind As String = "[0-9][0-9][0-9]"
Dim strSearch As String = "Test string 123 and another 456 and a third 789"
Dim strResults as New List(Of String)
Dim regLook As New Regex(strFind, RegexOptions.IgnoreCase)
Dim m As Match = regLook.Match(strSearch)
For Each mm As Match In m.Groups
 strResults.Add(mm.Value)
Next
or am I smoking crack?

Well, that looks about what I've been seeing. I think I'm just a little daunted by the wordiness of it, coming from Python. Ok, I'll sit down and try to work my way through that.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I found a solution that I think is easy enough for me to remember.

code:

        static void Main(string[] args)
        {
            string sPattern = ("\\d\\d\\d");
            string testString = "james is 123 and 456 and 83823 jas 432";

            Match foundMatches = Regex.Match(testString, sPattern);

            while(foundMatches.Success)
            {
                Console.WriteLine("I found {0}", foundMatches.Value);
                foundMatches = foundMatches.NextMatch();
            }


        }

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Munkeymon posted:

LINQPad might be a big help when you're trying to visualize object structure:


This is pretty cool, I'll have to check it out. I've seen the LINQ term being tossed about but I haven't really looked at it or know what it is.

I'm running into a new issue with my regex function. I'm capturing more characters than I want. An example test string would be:
code:
something something| ACCESS_ID:8812 something || jsme CUST_ID:998192 blah blah blah
My regex expression of "ACCESS_ID:(\d\d\d\d)" is capturing and printing out that entire block ACCESS_ID:8812 instead of just the number 8812. Any ideas on how I should adjust that?

*The ACCESS_ID: value can vary in length, won't always be 4 digits.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

fleshweasel posted:

Get just the capture group. Groups have automatic number identifiers or can be named. Google knows. Also, write \d{4} not \d\d\d\d.


Thanks, I was able to figure it out.

I was using foundPAT_ID.Value which gave me everything, turns out I needed foundPAT_ID.Groups[1].Value which gave me just the group I wanted captured.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
New to C# (have dabbled in Python and Perl). I am making a request to the RottenTomatoes API, and I end up with a string in JSON format. The string is essentially an array of dictionaries, full of movies. Example here: http://pastebin.com/CsbTNGqX

What would be the best way to iterate through each array element, printing out the movie title? Should I convert the string to a JSON object, and then try to work with that?

Hughmoris fucked around with this message at 01:15 on Nov 5, 2016

Hughmoris
Apr 21, 2007
Let's go to the abyss!

raminasi posted:

Yeah, define .NET types to mirror the structure of the JSON and then use Json.NET to convert it.

I just had my mind blow.

As mentioned, I'm extremely new to the language so I was trying to figure out how to create classes and properties to exactly mirror the structure of my JSON-formatted string, and I was flailing. I hopped on the ##csharp channel and someone told me about Visual Studios "edit -> paste special -> paste JSON as classes".

Coming from scratching the surface of Vim, that is seriously some magical poo poo. It created all of the classes and properties exactly as they needed to be, and my program worked.

Hughmoris fucked around with this message at 04:38 on Nov 5, 2016

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Cuntpunch posted:

These great features and more are waiting for you by just using F# - Call now for your introductory offer of Nobody Else Gets It Jesus Christ Why Cant We Use F# Around Here Come On Guys Its Not That Scary Wait What Are Those Pitchforks For

What are some of the projects/scripts you've used F# for?

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Cuntpunch posted:

Figuring out F# is my boredom project of the year, so it's not like I have F# in production to refer back to. So far a lot of it has been 'ok take a problem I'd consider trivial to solve in C# and figure out how to think about it from a different direction and work it out functionally.

My quip comes from experiences in trying to discuss how I've got this strong feeling there is really something super valuable there, and a lot of C# developers I know have the identical reaction of "But...why? I can do all of that faster and easier in C#!"

I'm a novice hobbyist and struggle with designing OOP stuff so I was curious about trying my hand at FP. I've heard good things about F#.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm a hobbyist programmer, and a novice with C#. I'd like to create a simple desktop app as an exercise to better learn how to create a GUI. I'm thinking the app will be used as a front-end to the StackOverflow database (local db) and the user can choose different query parameters and filters etc...

I'm not sure where to start. After doing some research/reading it seems like UWP is dead (long live UWP), WinForms is too old, WPF too hard, and something new called WinUI.

Any recommendations on where I should start?

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Thanks for the advice/thoughts on what GUI to start with.

Dumb question if I choose to pursue using a webapp instead of something like WPF:

Is it easy for webapps (such as a Blazor client-side app) to modify files on my local machine? An idea for my first app is a program that will read a folder full of media files on my laptop, present it as a fancy list to the user, and the user can rename the file and save.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
*Ignore this terrible snipe.

Hughmoris fucked around with this message at 21:44 on Apr 5, 2020

Hughmoris
Apr 21, 2007
Let's go to the abyss!
If I don't have admin rights for a Windows 10 machine, what are my options for learning C#?

I have a lot of downtime currently at my job. I have vscode installed but I can't install the dotnet sdk and trying to manually compile my cs file using csc.exe is failing as well.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Protocol7 posted:

Some cloud solution probably. At my old job when Accenture bought us out they came in with super draconian PC monitoring software and we couldn't even run Visual Studio for weeks. Nobody figured out a workaround, it was a fun few weeks.


Thanks. I don't think this will be an issue going forward since I got furloughed today. :suicide:

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Broad question here from a novice:

For those working in .NET, what field/domain are you working in? It seems like more and more of the popular blogs/articles/tutorials are focused on front-end webdev which I have zero interest or talent in. I think it could be interesting to build a desktop app but the general sentiment is "just build it with React".

So, for those of you not out there building websites, what do you build with .NET?

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Everyone posted:

What we do with .NET ...

Thanks for the insights, everyone. I think I'm going to try my hand at a simple Winforms app and see how it goes. My last foray into GUIs was Python + Tkinter ten years ago.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
A broad, novice question about profiling code:

The game Stardew Valley (uses XNA) allows people to create mods using C# solutions. Some mods can radically impact loading times of the game. For testing purposes, I created a "hello world" Mod then built the solution which generated a single .dll file and threw that in the game folder.

Is there any way to somehow hook onto the dll file being called and profile it's performance? Ultimately, my goal is to identify which of the 80+ mods being used are the culprit for the 7+ minute game load time.

I don't know what I don't know when it comes to Visual Studio and profiling capabilities but I'd love to take a stab at this.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

brap posted:

You can probably install perfview and take an ETL trace. Something comparable might also be possible within VS itself, but someone else would have to answer that.

I've never used perfview before but I'll give that a look, thanks!

Jabor posted:

If you're just looking for a single mod, have you considered a binary search? Disable half the mods, launch the game, see if it's slow. If it is, then you know the problem mod is one of the still-enabled ones - if it's faster, the problem mod is one that you've just disabled. Rinse and repeat, looking at a smaller subset each time.

Should only take 7 or 8 launches to figure out which mod is responsible.

I haven't tried that yet but might give it a go. Interwoven dependencies and large differences between Mod sizes for 70+ of them can mangle clean testing.

I think I just became overly motivated with profiling after reading this article about someone who cut load times for GTA V: Online by 70%.. The difference being they know what they're doing, and I don't.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
A novice question from a hobbyist:

Is it painful to call a F# library from Winforms or WPF? Can I:
  • write a simple parsing library in F#. Compile it.
  • Create a Winforms application in C#. Have an input field, click a button that calls the F# library to parse the input, then output the result to a new field.

At the 'Hello World' level so far, I enjoy writing in F#. But I want to create simple GUIs as well. Is combining both a bad path to take?

Adbot
ADBOT LOVES YOU

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I got a proof of concept working in the console. I'll take a look at those F# GUI frameworks. Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply