Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: Gonna Need an Extension

    CodeSOD: Gonna Need an Extension

    June 12, 2024

    Ever since the DOS days, determining file type based on the three letter extension in its filename has been a common practice. I’d argue that it’s not a good practice, but it’s become so standard that it’s hard to avoid. It’s so common that pretty much any language in wide use has some sort of “get extension” method. C# is no exception.

    Of course, having a convenient and commonly used helper method is no barrier to writing it yourself, and Andrew found this code in their application, which is meant to extract “png”, or “jpg” as the extension.

    /// <summary>
    /// This method returns the last three chars of the user ID using the image
    /// </summary>
    private string GetLastThreeCharsUID(string strImageName)
    {

    int intDotCount = 0;
    int intDotIndex = 0;
    string strSegment = “”;
    string strSplit = strImageName;

    //Get the last dot in the string
    {
    while (!(intDotCount == -1))
    {
    intDotCount = strSplit.IndexOf(‘.’);
    if (intDotCount != -1)
    {
    intDotIndex = strSplit.IndexOf(‘.’);
    strSegment = strSegment + strSplit.Substring(0, intDotIndex + 1);
    int intLength = (strSplit.Length – (intDotIndex + 1));
    strSplit = strSplit.Substring(intDotIndex + 1, intLength);
    }
    }
    }

    if (intDotIndex != -1)
    {
    return strImageName.Substring(intDotIndex – 3, 3);
    }
    else
    {
    return “Error”;
    }

    }

    The name of this function, and its comments, get us confused. “the last three chars of the user ID using the image”. What? Is… their user ID an image? That can’t be, can it? This has to be a copy-paste error, where they are claiming this has something to do with user IDs but doesn’t. Right? Right?

    Our approach to finding the the last . in the string is… spectacular. We check the IndexOf the dot, and if there is one, we split the string on the first dot. We stuff the first portion of the string into strSegment (which we never use), and then split on the next dot, until there are no more dots to split on.

    Finally, we take a substring on what we believe to be the prefix- I think. I’m not sure why it’s intDotIndex – 3. The fact that we only grab three characters means I hope nobody uploaded a jpeg or webm file.

    It’s a pretty impressive block of code, honestly. Certainly one of the hardest ways we could find to do this. It’s stuffed with so many choices that leave me scratching my head.

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleSELKS – live distribution for network security management
    Next Article syncBackup – backup and mirror your drives

    Related Posts

    Machine Learning

    Salesforce AI Releases BLIP3-o: A Fully Open-Source Unified Multimodal Model Built with CLIP Embeddings and Flow Matching for Image Understanding and Generation

    May 16, 2025
    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    AI in the Banking Sector: Customer Experience, Benefits, and Challenges

    Development

    How to screen-mirror an iPhone to a Samsung TV

    Development

    Salesforce AI Research Introduces New Benchmarks, Guardrails, and Model Architectures to Advance Trustworthy and Capable AI Agents

    Machine Learning

    Using Relative Date Helpers in Laravel’s Query Builder

    Development

    Highlights

    Transfer Learning for Structured Pruning under Limited Task Data

    July 10, 2024

    This paper was accepted at the Efficient Natural Language and Speech Processing (ENLSP-III) Workshop at…

    New Linux Variant of Play Ransomware Targeting VMware ESXi Systems

    July 26, 2024

    Web Scraping for Market Research

    May 10, 2024

    I’m aghast, stunned, and flabbergasted that Microsoft just removed the thesaurus from Word

    January 22, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.