[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"site-config":3,"blog-categories":6,"course-tree":34,"blog:post:string-contains-python":36,"blog:page:1":541},{"data":4},{"google_site_verification":5,"ga4_measurement_id":5,"site_name":5,"default_og_image":5,"twitter_handle":5},null,{"data":7},[8,14,19,24,29],{"name":9,"slug":10,"description":11,"post_count":12,"subcategories":13},"CSS","css","Learn CSS with practical tutorials and examples covering layouts, Flexbox, Grid, responsive design, typography, positioning, animations, and more.",1,[],{"name":15,"slug":16,"description":17,"post_count":12,"subcategories":18},"HTML","html","Learn HTML with practical tutorials and examples for beginners. Explore HTML tags, elements, attributes, links, images, forms, semantic HTML, and more with clear explanations and real code examples.",[],{"name":20,"slug":21,"description":22,"post_count":12,"subcategories":23},"WPF","wpf","Learn WPF with practical tutorials and examples covering XAML, windows, controls, layouts, data binding, MVVM, commands, styles, templates, debugging, and modern WPF UI development.",[],{"name":25,"slug":26,"description":27,"post_count":12,"subcategories":28},"Python","python","Learn Python with practical tutorials covering strings, lists, functions, exceptions, files, packages, virtual environments, modules, classes, and beginner programming concepts.",[],{"name":30,"slug":31,"description":32,"post_count":12,"subcategories":33},"Java","java","Learn Java with practical tutorials and examples for beginners. Explore Java syntax, variables, data types, classes, objects, methods, inheritance, exceptions, collections, and more with clear explanations and real code examples.",[],{"data":35},[],{"data":37},{"id":38,"title":39,"slug":40,"excerpt":41,"author":42,"categories":48,"featured_image":50,"reading_time_minutes":54,"meta_title":39,"meta_description":41,"og_image":5,"meta_robots":55,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":57,"published_at":107,"updated_at":108,"content":109,"related":110},4,"How to Check if a String Contains a Word in Python","string-contains-python","The direct way to check if a string contains a word in Python, plus whole-word matching, case-insensitive search, and finding word positions.",{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":45,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":46,"posts":47},"badar-khalil","Badar Khalil",[],[],[],[49],{"name":25,"slug":26},{"url":51,"alt_text":5,"width":52,"height":53},"https:\u002F\u002Fwpfsharp.com\u002Fstorage\u002Fblog\u002Ffeatured\u002Fstring-contains-python_1.webp",1200,628,10,[],"Article",[58,63,67,71,75,79,83,87,91,95,99,103],{"id":59,"text":60,"level":61,"children":62},"the-direct-answer-use-the-in-operator","The Direct Answer: Use the in Operator",3,[],{"id":64,"text":65,"level":61,"children":66},"in-finds-substrings-not-whole-words","in Finds Substrings, Not Whole Words",[],{"id":68,"text":69,"level":61,"children":70},"how-to-match-a-whole-word-instead-of-any-substring","How to Match a Whole Word Instead of Any Substring",[],{"id":72,"text":73,"level":61,"children":74},"case-insensitive-substring-and-word-checks","Case-Insensitive Substring and Word Checks",[],{"id":76,"text":77,"level":61,"children":78},"finding-where-a-match-occurs-find-and-index","Finding Where a Match Occurs: find() and index()",[],{"id":80,"text":81,"level":61,"children":82},"counting-matches-with-count","Counting Matches with count()",[],{"id":84,"text":85,"level":61,"children":86},"checking-several-words-at-once","Checking Several Words at Once",[],{"id":88,"text":89,"level":61,"children":90},"using-regular-expressions-for-pattern-based-text-search","Using Regular Expressions for Pattern-Based Text Search",[],{"id":92,"text":93,"level":61,"children":94},"common-pitfalls-at-a-glance","Common Pitfalls at a Glance",[],{"id":96,"text":97,"level":61,"children":98},"choosing-the-right-method","Choosing the Right Method",[],{"id":100,"text":101,"level":61,"children":102},"frequently-asked-questions","Frequently Asked Questions",[],{"id":104,"text":105,"level":61,"children":106},"conclusion","Conclusion",[],"2026-09-09T16:50:55+00:00","2026-09-09T16:53:02+00:00","\u003Cp>The simplest way to check if a string contains a word in Python is the \u003Ccode>in\u003C\u002Fcode> operator:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">if \"word\" in text:\n    ...\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>It returns \u003Ccode>True\u003C\u002Fcode> or \u003Ccode>False\u003C\u002Fcode> immediately, needs no import, and is the right first choice for a plain substring check. That single line covers most versions of this question. Things get more specific when you need a real whole word instead of any matching substring, or the exact position of a match, cases where \u003Ccode>in\u003C\u002Fcode> alone isn't the right tool. This guide covers each of those, along with the mistakes that trip people up.\u003C\u002Fp>\u003Ch3 id=\"the-direct-answer-use-the-in-operator\">The Direct Answer: Use the \u003Ccode>in\u003C\u002Fcode> Operator\u003C\u002Fh3>\u003Cp>\u003Ccode>in\u003C\u002Fcode> is a membership test built into Python strings. It scans the string and returns a boolean, nothing more.\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"Please check your order status before contacting support.\"\n\nif \"order\" in text:\n    print(\"Found it!\")\nelse:\n    print(\"Not found.\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>For the opposite check, use \u003Ccode>not in\u003C\u002Fcode>:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"Your package has shipped.\"\n\nif \"cancelled\" not in text:\n    print(\"Order is still active.\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>One edge case worth knowing: Python treats the empty string as a substring of every string, so \u003Ccode>\"\" in \"anything\"\u003C\u002Fcode> evaluates to \u003Ccode>True\u003C\u002Fcode>. It rarely comes up in practice, but it can surprise you if a search term is ever empty by accident, such as from unvalidated user input.\u003C\u002Fp>\u003Ch3 id=\"in-finds-substrings-not-whole-words\">\u003Ccode>in\u003C\u002Fcode> Finds Substrings, Not Whole Words\u003C\u002Fh3>\u003Cp>\u003Ccode>in\u003C\u002Fcode> has no concept of a \"word.\" It only checks whether one sequence of characters appears inside another, wherever that happens to be.\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">&gt;&gt;&gt; \"cat\" in \"category\"\nTrue\n&gt;&gt;&gt; \"cat\" in \"concatenate\"\nTrue\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>Both return \u003Ccode>True\u003C\u002Fcode> because \u003Ccode>cat\u003C\u002Fcode> genuinely occurs as a run of characters in each string, even though neither string is about a cat. This becomes a real bug when you're filtering text by keyword:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">messages = [\"Check out my spammer report\", \"This is not spam\", \"spa reservations\"]\nflagged = [m for m in messages if \"spam\" in m]\nprint(flagged)\n# ['Check out my spammer report', 'This is not spam']\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>The first message gets flagged only because \"spammer\" happens to contain \"spam\" as a substring. If that's not what you want, you need whole-word matching instead, which is a different, more specific check.\u003C\u002Fp>\u003Ch3 id=\"how-to-match-a-whole-word-instead-of-any-substring\">How to Match a Whole Word Instead of Any Substring\u003C\u002Fh3>\u003Ch4 id=\"splitting-the-text-first\">Splitting the Text First\u003C\u002Fh4>\u003Cp>For text with no punctuation attached to the words you care about, splitting into tokens and checking list membership avoids the substring problem entirely:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"This is not spam please stop flagging it\"\nwords = text.split()\n\nprint(\"spam\" in words)      # True\nprint(\"spammer\" in words)   # False\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>\u003Ccode>split()\u003C\u002Fcode> breaks the string on whitespace by default, so each list entry is a complete token rather than an arbitrary run of characters. The limitation is punctuation: \u003Ccode>split()\u003C\u002Fcode> leaves it attached to the word, so on a string like \u003Ccode>\"not spam, please stop\"\u003C\u002Fcode>, the token is \u003Ccode>\"spam,\"\u003C\u002Fcode>, not \u003Ccode>\"spam\"\u003C\u002Fcode>, and \u003Ccode>\"spam\" in words\u003C\u002Fcode> would come back \u003Ccode>False\u003C\u002Fcode>.\u003C\u002Fp>\u003Ch4 id=\"tokenizing-text-that-includes-punctuation\">Tokenizing Text That Includes Punctuation\u003C\u002Fh4>\u003Cp>Rather than stripping out punctuation marks one at a time, \u003Ccode>re.findall(r\"\\w+\", text)\u003C\u002Fcode> pulls out word-like tokens directly, treating anything that isn't a letter, digit, or underscore as a separator:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">import re\n\ntext = \"This is not spam, please stop flagging it.\"\nwords = re.findall(r\"\\w+\", text)\n\nprint(\"spam\" in words)      # True\nprint(\"spammer\" in words)   # False\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch4 id=\"using-regex-word-boundaries\">Using Regex Word Boundaries\u003C\u002Fh4>\u003Cp>\u003Ccode>re.search()\u003C\u002Fcode> with a \u003Ccode>\\b\u003C\u002Fcode> word-boundary marker does a similar job without building an intermediate list, which is convenient when you just need a yes\u002Fno answer:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">import re\n\ntext = \"This is not spam, please stop flagging it.\"\n\nif re.search(r\"\\bspam\\b\", text):\n    print(\"Whole word match found\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>Per the Python documentation, \u003Ccode>\\b\u003C\u002Fcode> marks the boundary between a word character (\u003Ccode>\\w\u003C\u002Fcode>: letters, digits, and underscore) and anything that isn't, or between a word character and the start or end of the string. That's a boundary defined by character classes, not a linguistic definition of a word, and the difference matters in practice. Because a hyphen or an apostrophe counts as \"not a word character,\" \u003Ccode>\\bcat\\b\u003C\u002Fcode> matches the \"cat\" inside \u003Ccode>\"cat's\"\u003C\u002Fcode>, and \u003Ccode>\\bwell\\b\u003C\u002Fcode> matches the \"well\" inside \u003Ccode>\"well-known\"\u003C\u002Fcode>, even though a person might not consider either one a separate whole word:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">&gt;&gt;&gt; re.findall(r\"\\bcat\\b\", \"the cat's toy\")\n['cat']\n&gt;&gt;&gt; re.findall(r\"\\bwell\\b\", \"a well-known fact\")\n['well']\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>If that distinction matters for your text, such as needing hyphenated compounds treated as single units, a custom pattern or additional post-processing will be more reliable than \u003Ccode>\\b\u003C\u002Fcode> alone.\u003C\u002Fp>\u003Ch3 id=\"case-insensitive-substring-and-word-checks\">Case-Insensitive Substring and Word Checks\u003C\u002Fh3>\u003Ch4 id=\"lower-for-everyday-text\">\u003Ccode>lower()\u003C\u002Fcode> for Everyday Text\u003C\u002Fh4>\u003Cp>Text in the real world is inconsistent about capitalization. The common fix is lowercasing both sides before comparing:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"Your ORDER has shipped\"\nkeyword = \"order\"\n\nif keyword.lower() in text.lower():\n    print(\"Match found, case-insensitive\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch4 id=\"casefold-for-unicode-text\">\u003Ccode>casefold()\u003C\u002Fcode> for Unicode Text\u003C\u002Fh4>\u003Cp>\u003Ccode>lower()\u003C\u002Fcode> is fine for plain ASCII text, but it doesn't apply every Unicode case-folding rule. Python's \u003Ccode>str.casefold()\u003C\u002Fcode> is built specifically for caseless comparisons and handles more cases than \u003Ccode>lower()\u003C\u002Fcode>. The standard example is the German letter \"&szlig;\": \u003Ccode>lower()\u003C\u002Fcode> leaves it unchanged, while \u003Ccode>casefold()\u003C\u002Fcode> converts it to \"ss\", which is how the two spellings are expected to compare as equal.\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">&gt;&gt;&gt; \"stra&szlig;e\".lower() == \"strasse\"\nFalse\n&gt;&gt;&gt; \"stra&szlig;e\".casefold() == \"strasse\"\nTrue\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>For everyday English text, \u003Ccode>lower()\u003C\u002Fcode> and \u003Ccode>casefold()\u003C\u002Fcode> behave the same way, so \u003Ccode>lower()\u003C\u002Fcode> combined with \u003Ccode>in\u003C\u002Fcode> is a valid and common way to do a case-insensitive substring check. Reach for \u003Ccode>casefold()\u003C\u002Fcode> when your input might include non-English text and the comparison needs to hold up correctly.\u003C\u002Fp>\u003Ch4 id=\"combining-whole-word-and-case-insensitive-matching\">Combining Whole-Word and Case-Insensitive Matching\u003C\u002Fh4>\u003Cp>Regex isn't required for a plain case-insensitive substring check, \u003Ccode>lower()\u003C\u002Fcode> plus \u003Ccode>in\u003C\u002Fcode> already covers that. It becomes useful once you need whole-word and case-insensitive matching \u003Cem>together\u003C\u002Fem>, which \u003Ccode>re.IGNORECASE\u003C\u002Fcode> (or its short alias, \u003Ccode>re.I\u003C\u002Fcode>) handles in one pass:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">import re\n\ntext = \"Contact SUPPORT for help\"\n\nif re.search(r\"\\bsupport\\b\", text, re.IGNORECASE):\n    print(\"Match found\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3 id=\"finding-where-a-match-occurs-find-and-index\">Finding Where a Match Occurs: \u003Ccode>find()\u003C\u002Fcode> and \u003Ccode>index()\u003C\u002Fcode>\u003C\u002Fh3>\u003Cp>\u003Ccode>in\u003C\u002Fcode> tells you whether a match exists, but not where. When you need the position, use \u003Ccode>find()\u003C\u002Fcode> or \u003Ccode>index()\u003C\u002Fcode>, not as a \"better\" substitute for \u003Ccode>in\u003C\u002Fcode>, but for the extra information they provide.\u003C\u002Fp>\u003Ch4 id=\"find\">\u003Ccode>find()\u003C\u002Fcode>\u003C\u002Fh4>\u003Cp>\u003Ccode>str.find()\u003C\u002Fcode> returns the index of the first match, or \u003Ccode>-1\u003C\u002Fcode> if there isn't one.\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"The invoice number is 48291\"\nposition = text.find(\"invoice\")\nprint(position)  # 4\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>Here's a bug that catches experienced developers, too: using \u003Ccode>find()\u003C\u002Fcode> directly as a condition.\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"spam is not welcome here\"\n\nif text.find(\"spam\"):\n    print(\"Found spam\")\nelse:\n    print(\"No spam found\")\n# Prints \"No spam found\", which is wrong\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>\u003Ccode>\"spam\"\u003C\u002Fcode> is actually found at index \u003Ccode>0\u003C\u002Fcode>, but Python treats \u003Ccode>0\u003C\u002Fcode> as falsy in a boolean context, so the \u003Ccode>if\u003C\u002Fcode> branch never runs. Compare explicitly against \u003Ccode>-1\u003C\u002Fcode> instead:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">if text.find(\"spam\") != -1:\n    print(\"Found spam\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch4 id=\"index\">\u003Ccode>index()\u003C\u002Fcode>\u003C\u002Fh4>\u003Cp>\u003Ccode>str.index()\u003C\u002Fcode> behaves the same way as \u003Ccode>find()\u003C\u002Fcode>, except a failed search raises a \u003Ccode>ValueError\u003C\u002Fcode> instead of returning \u003Ccode>-1\u003C\u002Fcode>:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"The invoice number is 48291\"\n\ntry:\n    position = text.index(\"receipt\")\nexcept ValueError:\n    print(\"Word not found\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>Both methods also accept an optional starting index, which lets you continue searching past a match you've already found:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"spam and more spam\"\nfirst = text.find(\"spam\")        # 0\nsecond = text.find(\"spam\", first + 1)  # 14\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch4 id=\"find-vs-index\">\u003Ccode>find()\u003C\u002Fcode> vs. \u003Ccode>index()\u003C\u002Fcode>\u003C\u002Fh4>\u003Ctable>\u003Ctbody>\u003Ctr>\u003Cth rowspan=\"1\" colspan=\"1\">\u003Cp>Method\u003C\u002Fp>\u003C\u002Fth>\u003Cth rowspan=\"1\" colspan=\"1\">\u003Cp>When the Word Is Missing\u003C\u002Fp>\u003C\u002Fth>\u003Cth rowspan=\"1\" colspan=\"1\">\u003Cp>Best For\u003C\u002Fp>\u003C\u002Fth>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>find()\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Returns \u003Ccode>-1\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>A missing match is a normal outcome you'll check for\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>index()\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Raises \u003Ccode>ValueError\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>A missing match should be treated as an error\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Ch3 id=\"counting-matches-with-count\">Counting Matches with \u003Ccode>count()\u003C\u002Fcode>\u003C\u002Fh3>\u003Cp>\u003Ccode>in\u003C\u002Fcode> and \u003Ccode>find()\u003C\u002Fcode> only tell you about the first occurrence. \u003Ccode>str.count()\u003C\u002Fcode> tells you how many non-overlapping times a substring appears in the whole string, which matters if you care about frequency rather than just presence. Note that \"non-overlapping\" means \u003Ccode>\"aaa\".count(\"aa\")\u003C\u002Fcode> returns \u003Ccode>1\u003C\u002Fcode>, not \u003Ccode>2\u003C\u002Fcode>, since the second possible match would reuse a character already claimed by the first.\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"the cat sat on the mat with a cat and the dog\"\nprint(text.count(\"cat\"))  # 2\nprint(text.count(\"the\"))  # 3\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3 id=\"checking-several-words-at-once\">Checking Several Words at Once\u003C\u002Fh3>\u003Cp>\u003Ccode>any()\u003C\u002Fcode> checks whether at least one keyword matches; \u003Ccode>all()\u003C\u002Fcode> checks whether every keyword does. Per the Python documentation, both work through the iterable in order and return as soon as the outcome is known: \u003Ccode>any()\u003C\u002Fcode> on the first true value, \u003Ccode>all()\u003C\u002Fcode> on the first false value.\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"This email looks like a phishing attempt\"\nkeywords = [\"phishing\", \"scam\", \"fraud\"]\n\nif any(word in text for word in keywords):\n    print(\"Suspicious content detected\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">text = \"Order confirmed. Payment received. Shipping in progress.\"\nrequired = [\"order\", \"payment\", \"shipping\"]\n\nif all(word.lower() in text.lower() for word in required):\n    print(\"All required terms present\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3 id=\"using-regular-expressions-for-pattern-based-text-search\">Using Regular Expressions for Pattern-Based Text Search\u003C\u002Fh3>\u003Cp>Everything so far has searched for a fixed, literal piece of text. Regex is worth reaching for once you're matching a \u003Cem>shape\u003C\u002Fem> of text instead, something a plain substring check can't express: an ID number, an email-like pattern, or a word followed by digits.\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">import re\n\nlog_line = \"user_id: 48291 failed login attempt\"\nmatch = re.search(r\"user_id:\\s*(\\d+)\", log_line)\nif match:\n    print(match.group(1))  # 48291\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>There's no fixed word to search for here, only a pattern, which is exactly the kind of problem \u003Ccode>in\u003C\u002Fcode>, \u003Ccode>find()\u003C\u002Fcode>, and \u003Ccode>index()\u003C\u002Fcode> can't solve.\u003C\u002Fp>\u003Ch4 id=\"reescape-for-literal-text-inside-a-pattern\">\u003Ccode>re.escape()\u003C\u002Fcode> for Literal Text Inside a Pattern\u003C\u002Fh4>\u003Cp>Sometimes you need to drop a literal, non-pattern string into a larger regex, for example when combining a user-supplied search term with \u003Ccode>re.IGNORECASE\u003C\u002Fcode> or with other pattern pieces. Characters like \u003Ccode>.\u003C\u002Fcode>, \u003Ccode>*\u003C\u002Fcode>, and \u003Ccode>(\u003C\u002Fcode> carry special meaning in regex, so inserting unescaped text can change what the pattern actually matches. \u003Ccode>re.escape()\u003C\u002Fcode> neutralizes those characters so the text is matched literally:\u003C\u002Fp>\u003Cp>python\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-python\">import re\n\nuser_term = \"3.14\"\npattern = re.escape(user_term)\ntext = \"The value is 3.14 exactly, not 3x14\"\n\nif re.search(pattern, text):\n    print(\"Literal match found\")\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>Without \u003Ccode>re.escape()\u003C\u002Fcode>, the unescaped \u003Ccode>.\u003C\u002Fcode> in \u003Ccode>\"3.14\"\u003C\u002Fcode> would match any character, so the pattern would also match a string like \u003Ccode>\"3x14\"\u003C\u002Fcode>. \u003Ccode>re.escape()\u003C\u002Fcode> fixes that by matching the text exactly as written. It's a correctness fix for building a regex pattern, not a substitute for \u003Ccode>in\u003C\u002Fcode> when a plain substring check is all you need.\u003C\u002Fp>\u003Ch3 id=\"common-pitfalls-at-a-glance\">Common Pitfalls at a Glance\u003C\u002Fh3>\u003Cul>\u003Cli>\u003Cp>\u003Cstrong>Treating \u003C\u002Fstrong>\u003Ccode>in\u003C\u002Fcode>\u003Cstrong> as whole-word matching.\u003C\u002Fstrong> It matches substrings, so \u003Ccode>\"cat\" in \"category\"\u003C\u002Fcode> is \u003Ccode>True\u003C\u002Fcode>.\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Forgetting that string matching is case-sensitive by default.\u003C\u002Fstrong> \u003Ccode>\"Order\" in \"your order is ready\"\u003C\u002Fcode> is \u003Ccode>False\u003C\u002Fcode> unless you normalize the case first.\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Using \u003C\u002Fstrong>\u003Ccode>find()\u003C\u002Fcode>\u003Cstrong> directly in an \u003C\u002Fstrong>\u003Ccode>if\u003C\u002Fcode>\u003Cstrong>.\u003C\u002Fstrong> A match at index \u003Ccode>0\u003C\u002Fcode> is falsy in Python, so \u003Ccode>if text.find(\"word\"):\u003C\u002Fcode> silently fails for matches at the very start of the string.\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Letting \u003C\u002Fstrong>\u003Ccode>index()\u003C\u002Fcode>\u003Cstrong> raise on a normal \"not found\" case.\u003C\u002Fstrong> If a missing match is expected rather than exceptional, \u003Ccode>find()\u003C\u002Fcode> or \u003Ccode>in\u003C\u002Fcode> is usually the simpler choice.\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Assuming \u003C\u002Fstrong>\u003Ccode>\\b\u003C\u002Fcode>\u003Cstrong> matches a human's idea of a \"word.\"\u003C\u002Fstrong> It matches regex word-character boundaries, so it can split at hyphens and apostrophes in ways you might not expect.\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Reaching for regex when \u003C\u002Fstrong>\u003Ccode>in\u003C\u002Fcode>\u003Cstrong> already answers the question.\u003C\u002Fstrong> Regex adds real value for whole-word matching, case-insensitive-plus-whole-word combinations, and pattern-based searches; for a plain substring check, \u003Ccode>in\u003C\u002Fcode> is shorter to write and easier to read.\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Ch3 id=\"choosing-the-right-method\">Choosing the Right Method\u003C\u002Fh3>\u003Ctable>\u003Ctbody>\u003Ctr>\u003Cth rowspan=\"1\" colspan=\"1\">\u003Cp>Situation\u003C\u002Fp>\u003C\u002Fth>\u003Cth rowspan=\"1\" colspan=\"1\">\u003Cp>Recommended Method\u003C\u002Fp>\u003C\u002Fth>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Plain substring check\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>in\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Case-insensitive substring check\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>.lower()\u003C\u002Fcode> or \u003Ccode>.casefold()\u003C\u002Fcode> combined with \u003Ccode>in\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Whole-word match on text without punctuation\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>split()\u003C\u002Fcode> and list membership\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Whole-word match with punctuation\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>re.findall(r\"\\w+\", text)\u003C\u002Fcode> or \u003Ccode>re.search()\u003C\u002Fcode> with \u003Ccode>\\b\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Whole-word and case-insensitive together\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>re.search()\u003C\u002Fcode> with \u003Ccode>\\b\u003C\u002Fcode> and \u003Ccode>re.IGNORECASE\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Position of the first match\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>find()\u003C\u002Fcode> (expected miss) or \u003Ccode>index()\u003C\u002Fcode> (unexpected miss)\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Number of occurrences\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>count()\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Matching several possible words\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>any()\u003C\u002Fcode> or \u003Ccode>all()\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>Matching a pattern rather than fixed text\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd rowspan=\"1\" colspan=\"1\">\u003Cp>\u003Ccode>re\u003C\u002Fcode> module\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Ch3 id=\"frequently-asked-questions\">Frequently Asked Questions\u003C\u002Fh3>\u003Ch4 id=\"whats-the-simplest-way-to-check-if-a-string-contains-a-word-in-python\">\u003Cstrong>What's the simplest way to check if a string contains a word in Python?\u003C\u002Fstrong>\u003C\u002Fh4>\u003Cp>Use the \u003Ccode>in\u003C\u002Fcode> operator: \u003Ccode>\"word\" in text\u003C\u002Fcode>. It returns \u003Ccode>True\u003C\u002Fcode> if the substring is found anywhere in the string, \u003Ccode>False\u003C\u002Fcode> otherwise.\u003C\u002Fp>\u003Ch4 id=\"does-in-check-for-a-whole-word-or-just-a-substring\">\u003Cstrong>Does \u003C\u002Fstrong>\u003Ccode>in\u003C\u002Fcode>\u003Cstrong> check for a whole word or just a substring?\u003C\u002Fstrong>\u003C\u002Fh4>\u003Cp>A substring. \u003Ccode>\"cat\" in \"category\"\u003C\u002Fcode> returns \u003Ccode>True\u003C\u002Fcode> even though \"category\" isn't about a cat. For whole-word matching, split the text into tokens or use a regex pattern with \u003Ccode>\\b\u003C\u002Fcode>.\u003C\u002Fp>\u003Ch4 id=\"how-do-i-check-for-a-whole-word-instead-of-a-substring\">\u003Cstrong>How do I check for a whole word instead of a substring?\u003C\u002Fstrong>\u003C\u002Fh4>\u003Cp>Split clean, punctuation-free text into a list of words and check membership, or use \u003Ccode>re.search(r\"\\bword\\b\", text)\u003C\u002Fcode> for text with punctuation.\u003C\u002Fp>\u003Ch4 id=\"how-do-i-do-a-case-insensitive-check\">\u003Cstrong>How do I do a case-insensitive check?\u003C\u002Fstrong>\u003C\u002Fh4>\u003Cp>Lowercase both sides with \u003Ccode>.lower()\u003C\u002Fcode> before comparing, use \u003Ccode>.casefold()\u003C\u002Fcode> for text that may include non-English characters, or add \u003Ccode>re.IGNORECASE\u003C\u002Fcode> if you're already using regex for whole-word matching.\u003C\u002Fp>\u003Ch4 id=\"whats-the-difference-between-in-and-find\">\u003Cstrong>What's the difference between \u003C\u002Fstrong>\u003Ccode>in\u003C\u002Fcode>\u003Cstrong> and \u003C\u002Fstrong>\u003Ccode>find()\u003C\u002Fcode>\u003Cstrong>?\u003C\u002Fstrong>\u003C\u002Fh4>\u003Cp>\u003Ccode>in\u003C\u002Fcode> returns a boolean. \u003Ccode>find()\u003C\u002Fcode> returns the index of the first match, or \u003Ccode>-1\u003C\u002Fcode> if the word isn't present, which is useful when you need the position rather than a yes\u002Fno answer.\u003C\u002Fp>\u003Ch4 id=\"what-happens-when-index-cant-find-the-word\">\u003Cstrong>What happens when \u003C\u002Fstrong>\u003Ccode>index()\u003C\u002Fcode>\u003Cstrong> can't find the word?\u003C\u002Fstrong>\u003C\u002Fh4>\u003Cp>It raises a \u003Ccode>ValueError\u003C\u002Fcode>, unlike \u003Ccode>find()\u003C\u002Fcode>, which returns \u003Ccode>-1\u003C\u002Fcode>. Wrap \u003Ccode>index()\u003C\u002Fcode> in a \u003Ccode>try\u003C\u002Fcode>\u002F\u003Ccode>except\u003C\u002Fcode> block if a missing match is a real possibility.\u003C\u002Fp>\u003Ch4 id=\"how-do-i-check-if-any-of-several-words-are-present\">\u003Cstrong>How do I check if any of several words are present?\u003C\u002Fstrong>\u003C\u002Fh4>\u003Cp>Use \u003Ccode>any(word in text for word in keywords)\u003C\u002Fcode> if one match is enough, or \u003Ccode>all(...)\u003C\u002Fcode> if every keyword needs to be present.\u003C\u002Fp>\u003Ch3 id=\"conclusion\">Conclusion\u003C\u002Fh3>\u003Cp>For most cases, the \u003Ccode>in\u003C\u002Fcode> operator is all you need to check if a string contains a word in Python. \u003Ccode>find()\u003C\u002Fcode> and \u003Ccode>index()\u003C\u002Fcode> step in when you need the match's position instead of a yes\u002Fno answer, and \u003Ccode>count()\u003C\u002Fcode> answers \"how many.\" Reach for \u003Ccode>re\u003C\u002Fcode> once you need whole-word boundaries, case-insensitive matching combined with whole words, or a pattern rather than a fixed piece of text. Match the tool to what you actually need, and the rest of the code follows naturally.\u003C\u002Fp>",[111,253,474],{"id":112,"title":113,"slug":114,"excerpt":115,"author":116,"categories":120,"featured_image":122,"reading_time_minutes":54,"meta_title":5,"meta_description":115,"og_image":5,"meta_robots":125,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":126,"published_at":252,"updated_at":252},5,"How to Convert String to Int Java: parseInt(), valueOf() & More","how-to-convert-string-to-int-java-parseint-valueof-more","Learn how to convert string to int Java the right way with parseInt(), valueOf(), radix conversion, and safe NumberFormatException handling.",{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":117,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":118,"posts":119},[],[],[],[121],{"name":30,"slug":31},{"url":123,"alt_text":124,"width":5,"height":5},"\u002Fstorage\u002Fmedia\u002F01M23RNHPZVQHMX2DYD3YKQJF1.webp","String to int conversion in Java",[],[127,132,144,156,168,180,200,204,208,224,228],{"id":128,"text":129,"level":130,"children":131},"the-quickest-way-to-convert-string-to-int-java-values","The Quickest Way to Convert String to Int Java Values",2,[],{"id":133,"text":134,"level":130,"children":135},"convert-string-to-int-using-integerparseint","Convert String to Int Using Integer.parseInt()",[136,140],{"id":137,"text":138,"level":61,"children":139},"basic-parseint-syntax","Basic parseInt() Syntax",[],{"id":141,"text":142,"level":61,"children":143},"converting-user-input-to-an-int","Converting User Input to an Int",[],{"id":145,"text":146,"level":130,"children":147},"convert-string-to-integer-using-integervalueof","Convert String to Integer Using Integer.valueOf()",[148,152],{"id":149,"text":150,"level":61,"children":151},"how-integervalueof-works","How Integer.valueOf() Works",[],{"id":153,"text":154,"level":61,"children":155},"parseint-vs-valueof","parseInt() vs valueOf()",[],{"id":157,"text":158,"level":130,"children":159},"convert-a-string-using-a-different-number-base","Convert a String Using a Different Number Base",[160,164],{"id":161,"text":162,"level":61,"children":163},"convert-binary-octal-or-hexadecimal-strings-with-a-radix","Convert Binary, Octal, or Hexadecimal Strings with a Radix",[],{"id":165,"text":166,"level":61,"children":167},"when-to-use-integerdecode","When to Use Integer.decode()",[],{"id":169,"text":170,"level":130,"children":171},"handle-invalid-strings-with-numberformatexception","Handle Invalid Strings with NumberFormatException",[172,176],{"id":173,"text":174,"level":61,"children":175},"what-happens-when-a-string-is-not-a-valid-integer","What Happens When a String Is Not a Valid Integer",[],{"id":177,"text":178,"level":61,"children":179},"safely-convert-user-or-external-input","Safely Convert User or External Input",[],{"id":181,"text":182,"level":130,"children":183},"common-string-to-int-problems-in-java","Common String-to-Int Problems in Java",[184,188,192,196],{"id":185,"text":186,"level":61,"children":187},"leading-and-trailing-whitespace","Leading and Trailing Whitespace",[],{"id":189,"text":190,"level":61,"children":191},"null-strings","Null Strings",[],{"id":193,"text":194,"level":61,"children":195},"decimal-and-formatted-numbers","Decimal and Formatted Numbers",[],{"id":197,"text":198,"level":61,"children":199},"values-outside-the-int-range","Values Outside the int Range",[],{"id":201,"text":202,"level":130,"children":203},"which-string-to-int-java-method-should-you-use","Which String to Int Java Method Should You Use?",[],{"id":205,"text":206,"level":130,"children":207},"common-mistakes-to-avoid-when-converting-string-to-int","Common Mistakes to Avoid When Converting String to Int",[],{"id":209,"text":210,"level":130,"children":211},"practical-examples-of-string-to-int-conversion","Practical Examples of String-to-Int Conversion",[212,216,220],{"id":213,"text":214,"level":61,"children":215},"convert-a-string-before-performing-arithmetic","Convert a String Before Performing Arithmetic",[],{"id":217,"text":218,"level":61,"children":219},"convert-multiple-string-values","Convert Multiple String Values",[],{"id":221,"text":222,"level":61,"children":223},"convert-a-string-safely-in-a-real-world-input-flow","Convert a String Safely in a Real-World Input Flow",[],{"id":225,"text":226,"level":130,"children":227},"wrapping-up","Wrapping Up",[],{"id":229,"text":230,"level":130,"children":231},"frequently-asked-questions-about-string-to-int-in-java","Frequently Asked Questions About String to Int in Java",[232,236,240,244,248],{"id":233,"text":234,"level":61,"children":235},"what-is-the-easiest-way-to-convert-a-string-to-int-in-java","What is the easiest way to convert a String to int in Java?",[],{"id":237,"text":238,"level":61,"children":239},"what-is-the-difference-between-parseint-and-valueof-in-java","What is the difference between parseInt() and valueOf() in Java?",[],{"id":241,"text":242,"level":61,"children":243},"how-do-i-convert-a-string-to-int-without-getting-numberformatexception","How do I convert a String to int without getting NumberFormatException?",[],{"id":245,"text":246,"level":61,"children":247},"can-i-convert-a-decimal-string-directly-to-an-int-in-java","Can I convert a decimal String directly to an int in Java?",[],{"id":249,"text":250,"level":61,"children":251},"how-do-i-convert-a-binary-or-hexadecimal-string-to-an-int-in-java","How do I convert a binary or hexadecimal String to an int in Java?",[],"2026-09-09T19:09:06+00:00",{"id":61,"title":254,"slug":255,"excerpt":256,"author":257,"categories":261,"featured_image":263,"reading_time_minutes":266,"meta_title":267,"meta_description":256,"og_image":5,"meta_robots":268,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":269,"published_at":473,"updated_at":473},"What Is WPF in C#? A Complete Guide to Windows Presentation Foundation","what-is-wpf-in-csharp","What is WPF in C#? A clear guide to Windows Presentation Foundation, how it works with C# and XAML, and whether it's worth learning in 2026.",{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":258,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":259,"posts":260},[],[],[],[262],{"name":20,"slug":21},{"url":264,"alt_text":265,"width":5,"height":5},"\u002Fstorage\u002Fmedia\u002F01M20ZGFAW00NYSYC5YMV0SG53.webp","WPF in C# complete guide infographic featuring Visual Studio XAML designer, data binding architecture, MVVM pattern icons, and C# code logic on a laptop screen.",13,"What Is WPF in C#?",[],[270,281,293,309,317,349,365,389,405,413,429,449,461,465,469],{"id":271,"text":267,"level":130,"children":272},"what-is-wpf-in-c",[273,277],{"id":274,"text":275,"level":61,"children":276},"is-wpf-part-of-c-or-net","Is WPF Part of C# or .NET?",[],{"id":278,"text":279,"level":61,"children":280},"what-does-wpf-stand-for","What Does WPF Stand For?",[],{"id":282,"text":283,"level":130,"children":284},"what-is-wpf-used-for","What Is WPF Used For?",[285,289],{"id":286,"text":287,"level":61,"children":288},"what-can-you-build-with-wpf","What Can You Build With WPF?",[],{"id":290,"text":291,"level":61,"children":292},"what-cant-wpf-be-used-for","What Can't WPF Be Used For?",[],{"id":294,"text":295,"level":130,"children":296},"how-does-wpf-work-with-c","How Does WPF Work With C#?",[297,301,305],{"id":298,"text":299,"level":61,"children":300},"what-is-xaml-in-wpf","What Is XAML in WPF?",[],{"id":302,"text":303,"level":61,"children":304},"what-is-code-behind-in-wpf","What Is Code-Behind in WPF?",[],{"id":306,"text":307,"level":61,"children":308},"simple-wpf-xaml-and-c-example","Simple WPF XAML and C# Example",[],{"id":310,"text":311,"level":130,"children":312},"how-is-a-wpf-application-structured","How Is a WPF Application Structured?",[313],{"id":314,"text":315,"level":61,"children":316},"how-xaml-c-and-wpf-work-together","How XAML, C#, and WPF Work Together",[],{"id":318,"text":319,"level":130,"children":320},"key-features-of-wpf","Key Features of WPF",[321,325,329,333,337,341,345],{"id":322,"text":323,"level":61,"children":324},"xaml-based-ui","XAML-Based UI",[],{"id":326,"text":327,"level":61,"children":328},"data-binding","Data Binding",[],{"id":330,"text":331,"level":61,"children":332},"dependency-properties","Dependency Properties",[],{"id":334,"text":335,"level":61,"children":336},"routed-events","Routed Events",[],{"id":338,"text":339,"level":61,"children":340},"styles-and-control-templates","Styles and Control Templates",[],{"id":342,"text":343,"level":61,"children":344},"wpf-layout-system","WPF Layout System",[],{"id":346,"text":347,"level":61,"children":348},"graphics-and-animation","Graphics and Animation",[],{"id":350,"text":351,"level":130,"children":352},"what-is-data-binding-in-wpf","What Is Data Binding in WPF?",[353,357,361],{"id":354,"text":355,"level":61,"children":356},"how-wpf-data-binding-works","How WPF Data Binding Works",[],{"id":358,"text":359,"level":61,"children":360},"simple-data-binding-example","Simple Data Binding Example",[],{"id":362,"text":363,"level":61,"children":364},"why-data-binding-matters-in-wpf","Why Data Binding Matters in WPF",[],{"id":366,"text":367,"level":130,"children":368},"what-is-mvvm-in-wpf","What Is MVVM in WPF?",[369,373,377,381,385],{"id":370,"text":371,"level":61,"children":372},"model","Model",[],{"id":374,"text":375,"level":61,"children":376},"view","View",[],{"id":378,"text":379,"level":61,"children":380},"viewmodel","ViewModel",[],{"id":382,"text":383,"level":61,"children":384},"why-is-mvvm-commonly-used-with-wpf","Why Is MVVM Commonly Used With WPF?",[],{"id":386,"text":387,"level":61,"children":388},"is-mvvm-required-for-wpf","Is MVVM Required for WPF?",[],{"id":390,"text":391,"level":130,"children":392},"how-to-create-a-wpf-application-in-c","How to Create a WPF Application in C#",[393,397,401],{"id":394,"text":395,"level":61,"children":396},"what-you-need","What You Need",[],{"id":398,"text":399,"level":61,"children":400},"create-a-wpf-project","Create a WPF Project",[],{"id":402,"text":403,"level":61,"children":404},"build-and-run-your-first-wpf-app","Build and Run Your First WPF App",[],{"id":406,"text":407,"level":130,"children":408},"wpf-vs-windows-forms","WPF vs Windows Forms",[409],{"id":410,"text":411,"level":61,"children":412},"which-is-better-wpf-or-winforms","Which Is Better: WPF or WinForms?",[],{"id":414,"text":415,"level":130,"children":416},"wpf-vs-winui-3","WPF vs WinUI 3",[417,421,425],{"id":418,"text":419,"level":61,"children":420},"what-is-winui-3","What Is WinUI 3?",[],{"id":422,"text":423,"level":61,"children":424},"wpf-vs-winui-3-main-differences","WPF vs WinUI 3: Main Differences",[],{"id":426,"text":427,"level":61,"children":428},"should-you-learn-wpf-or-winui","Should You Learn WPF or WinUI?",[],{"id":430,"text":431,"level":130,"children":432},"is-wpf-still-relevant-in-2026","Is WPF Still Relevant in 2026?",[433,437,441,445],{"id":434,"text":435,"level":61,"children":436},"is-wpf-still-supported","Is WPF Still Supported?",[],{"id":438,"text":439,"level":61,"children":440},"does-wpf-work-with-modern-net","Does WPF Work With Modern .NET?",[],{"id":442,"text":443,"level":61,"children":444},"is-wpf-still-used-for-business-applications","Is WPF Still Used for Business Applications?",[],{"id":446,"text":447,"level":61,"children":448},"should-you-learn-wpf-today","Should You Learn WPF Today?",[],{"id":450,"text":451,"level":130,"children":452},"advantages-and-disadvantages-of-wpf","Advantages and Disadvantages of WPF",[453,457],{"id":454,"text":455,"level":61,"children":456},"advantages-of-wpf","Advantages of WPF",[],{"id":458,"text":459,"level":61,"children":460},"disadvantages-of-wpf","Disadvantages of WPF",[],{"id":462,"text":463,"level":130,"children":464},"common-wpf-terms-beginners-should-know","Common WPF Terms Beginners Should Know",[],{"id":466,"text":467,"level":130,"children":468},"frequently-asked-questions-about-wpf-in-c","Frequently Asked Questions About WPF in C#",[],{"id":470,"text":471,"level":130,"children":472},"final-answer-what-is-wpf-in-c","Final Answer: What Is WPF in C#?",[],"2026-09-08T17:04:51+00:00",{"id":130,"title":475,"slug":476,"excerpt":477,"author":478,"categories":482,"featured_image":484,"reading_time_minutes":487,"meta_title":488,"meta_description":477,"og_image":5,"meta_robots":489,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":490,"published_at":539,"updated_at":540},"How to Add an Image in HTML: The Complete img Tag Guide","how-to-add-an-image-in-html","Learn how to add image in HTML with the img tag, alt text, relative paths, srcset, and the picture element — plus common mistakes to avoid.",{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":479,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":480,"posts":481},[],[],[],[483],{"name":15,"slug":16},{"url":485,"alt_text":486,"width":5,"height":5},"\u002Fstorage\u002Fmedia\u002F01M20TNJ8K254FH80P5N6V87PR.webp","How to add an image in HTML using the img tag, responsive images, and alt text",6,"How to Add Image in HTML",[],[491,495,499,503,507,511,515,519,523,527,531,535],{"id":492,"text":493,"level":130,"children":494},"the-basic-syntax-for-how-to-add-image-in-html","The Basic Syntax for How to Add Image in HTML",[],{"id":496,"text":497,"level":130,"children":498},"understanding-the-img-tags-core-attributes","Understanding the img Tag's Core Attributes",[],{"id":500,"text":501,"level":130,"children":502},"relative-root-relative-and-absolute-urls-for-images","Relative, Root-Relative, and Absolute URLs for Images",[],{"id":504,"text":505,"level":130,"children":506},"making-images-responsive-with-srcset-and-sizes","Making Images Responsive with srcset and sizes",[],{"id":508,"text":509,"level":130,"children":510},"using-the-picture-element-for-format-fallbacks","Using the picture Element for Format Fallbacks",[],{"id":512,"text":513,"level":130,"children":514},"wrapping-images-with-figure-and-figcaption","Wrapping Images with figure and figcaption",[],{"id":516,"text":517,"level":130,"children":518},"making-an-image-clickable","Making an Image Clickable",[],{"id":520,"text":521,"level":130,"children":522},"lazy-loading-images-for-performance","Lazy Loading Images for Performance",[],{"id":524,"text":525,"level":130,"children":526},"common-mistakes-when-adding-images-in-html","Common Mistakes When Adding Images in HTML",[],{"id":528,"text":529,"level":130,"children":530},"quick-reference-which-approach-fits-your-situation","Quick Reference: Which Approach Fits Your Situation",[],{"id":532,"text":533,"level":130,"children":534},"faq-about-adding-images-in-html","FAQ About Adding Images in HTML",[],{"id":536,"text":537,"level":130,"children":538},"the-short-version","The Short Version",[],"2026-09-08T15:41:06+00:00","2026-09-08T20:23:09+00:00",{"data":542,"links":859,"meta":861},[543,615,649,761,795],{"id":112,"title":113,"slug":114,"excerpt":115,"author":544,"categories":548,"featured_image":550,"reading_time_minutes":54,"meta_title":5,"meta_description":115,"og_image":5,"meta_robots":551,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":552,"published_at":252,"updated_at":252},{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":545,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":546,"posts":547},[],[],[],[549],{"name":30,"slug":31},{"url":123,"alt_text":124,"width":5,"height":5},[],[553,555,561,567,573,579,589,591,593,601,603],{"id":128,"text":129,"level":130,"children":554},[],{"id":133,"text":134,"level":130,"children":556},[557,559],{"id":137,"text":138,"level":61,"children":558},[],{"id":141,"text":142,"level":61,"children":560},[],{"id":145,"text":146,"level":130,"children":562},[563,565],{"id":149,"text":150,"level":61,"children":564},[],{"id":153,"text":154,"level":61,"children":566},[],{"id":157,"text":158,"level":130,"children":568},[569,571],{"id":161,"text":162,"level":61,"children":570},[],{"id":165,"text":166,"level":61,"children":572},[],{"id":169,"text":170,"level":130,"children":574},[575,577],{"id":173,"text":174,"level":61,"children":576},[],{"id":177,"text":178,"level":61,"children":578},[],{"id":181,"text":182,"level":130,"children":580},[581,583,585,587],{"id":185,"text":186,"level":61,"children":582},[],{"id":189,"text":190,"level":61,"children":584},[],{"id":193,"text":194,"level":61,"children":586},[],{"id":197,"text":198,"level":61,"children":588},[],{"id":201,"text":202,"level":130,"children":590},[],{"id":205,"text":206,"level":130,"children":592},[],{"id":209,"text":210,"level":130,"children":594},[595,597,599],{"id":213,"text":214,"level":61,"children":596},[],{"id":217,"text":218,"level":61,"children":598},[],{"id":221,"text":222,"level":61,"children":600},[],{"id":225,"text":226,"level":130,"children":602},[],{"id":229,"text":230,"level":130,"children":604},[605,607,609,611,613],{"id":233,"text":234,"level":61,"children":606},[],{"id":237,"text":238,"level":61,"children":608},[],{"id":241,"text":242,"level":61,"children":610},[],{"id":245,"text":246,"level":61,"children":612},[],{"id":249,"text":250,"level":61,"children":614},[],{"id":38,"title":39,"slug":40,"excerpt":41,"author":616,"categories":620,"featured_image":622,"reading_time_minutes":54,"meta_title":39,"meta_description":41,"og_image":5,"meta_robots":623,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":624,"published_at":107,"updated_at":108},{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":617,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":618,"posts":619},[],[],[],[621],{"name":25,"slug":26},{"url":51,"alt_text":5,"width":52,"height":53},[],[625,627,629,631,633,635,637,639,641,643,645,647],{"id":59,"text":60,"level":61,"children":626},[],{"id":64,"text":65,"level":61,"children":628},[],{"id":68,"text":69,"level":61,"children":630},[],{"id":72,"text":73,"level":61,"children":632},[],{"id":76,"text":77,"level":61,"children":634},[],{"id":80,"text":81,"level":61,"children":636},[],{"id":84,"text":85,"level":61,"children":638},[],{"id":88,"text":89,"level":61,"children":640},[],{"id":92,"text":93,"level":61,"children":642},[],{"id":96,"text":97,"level":61,"children":644},[],{"id":100,"text":101,"level":61,"children":646},[],{"id":104,"text":105,"level":61,"children":648},[],{"id":61,"title":254,"slug":255,"excerpt":256,"author":650,"categories":654,"featured_image":656,"reading_time_minutes":266,"meta_title":267,"meta_description":256,"og_image":5,"meta_robots":657,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":658,"published_at":473,"updated_at":473},{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":651,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":652,"posts":653},[],[],[],[655],{"name":20,"slug":21},{"url":264,"alt_text":265,"width":5,"height":5},[],[659,665,671,679,683,699,707,719,727,731,739,749,755,757,759],{"id":271,"text":267,"level":130,"children":660},[661,663],{"id":274,"text":275,"level":61,"children":662},[],{"id":278,"text":279,"level":61,"children":664},[],{"id":282,"text":283,"level":130,"children":666},[667,669],{"id":286,"text":287,"level":61,"children":668},[],{"id":290,"text":291,"level":61,"children":670},[],{"id":294,"text":295,"level":130,"children":672},[673,675,677],{"id":298,"text":299,"level":61,"children":674},[],{"id":302,"text":303,"level":61,"children":676},[],{"id":306,"text":307,"level":61,"children":678},[],{"id":310,"text":311,"level":130,"children":680},[681],{"id":314,"text":315,"level":61,"children":682},[],{"id":318,"text":319,"level":130,"children":684},[685,687,689,691,693,695,697],{"id":322,"text":323,"level":61,"children":686},[],{"id":326,"text":327,"level":61,"children":688},[],{"id":330,"text":331,"level":61,"children":690},[],{"id":334,"text":335,"level":61,"children":692},[],{"id":338,"text":339,"level":61,"children":694},[],{"id":342,"text":343,"level":61,"children":696},[],{"id":346,"text":347,"level":61,"children":698},[],{"id":350,"text":351,"level":130,"children":700},[701,703,705],{"id":354,"text":355,"level":61,"children":702},[],{"id":358,"text":359,"level":61,"children":704},[],{"id":362,"text":363,"level":61,"children":706},[],{"id":366,"text":367,"level":130,"children":708},[709,711,713,715,717],{"id":370,"text":371,"level":61,"children":710},[],{"id":374,"text":375,"level":61,"children":712},[],{"id":378,"text":379,"level":61,"children":714},[],{"id":382,"text":383,"level":61,"children":716},[],{"id":386,"text":387,"level":61,"children":718},[],{"id":390,"text":391,"level":130,"children":720},[721,723,725],{"id":394,"text":395,"level":61,"children":722},[],{"id":398,"text":399,"level":61,"children":724},[],{"id":402,"text":403,"level":61,"children":726},[],{"id":406,"text":407,"level":130,"children":728},[729],{"id":410,"text":411,"level":61,"children":730},[],{"id":414,"text":415,"level":130,"children":732},[733,735,737],{"id":418,"text":419,"level":61,"children":734},[],{"id":422,"text":423,"level":61,"children":736},[],{"id":426,"text":427,"level":61,"children":738},[],{"id":430,"text":431,"level":130,"children":740},[741,743,745,747],{"id":434,"text":435,"level":61,"children":742},[],{"id":438,"text":439,"level":61,"children":744},[],{"id":442,"text":443,"level":61,"children":746},[],{"id":446,"text":447,"level":61,"children":748},[],{"id":450,"text":451,"level":130,"children":750},[751,753],{"id":454,"text":455,"level":61,"children":752},[],{"id":458,"text":459,"level":61,"children":754},[],{"id":462,"text":463,"level":130,"children":756},[],{"id":466,"text":467,"level":130,"children":758},[],{"id":470,"text":471,"level":130,"children":760},[],{"id":130,"title":475,"slug":476,"excerpt":477,"author":762,"categories":766,"featured_image":768,"reading_time_minutes":487,"meta_title":488,"meta_description":477,"og_image":5,"meta_robots":769,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":770,"published_at":539,"updated_at":540},{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":763,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":764,"posts":765},[],[],[],[767],{"name":15,"slug":16},{"url":485,"alt_text":486,"width":5,"height":5},[],[771,773,775,777,779,781,783,785,787,789,791,793],{"id":492,"text":493,"level":130,"children":772},[],{"id":496,"text":497,"level":130,"children":774},[],{"id":500,"text":501,"level":130,"children":776},[],{"id":504,"text":505,"level":130,"children":778},[],{"id":508,"text":509,"level":130,"children":780},[],{"id":512,"text":513,"level":130,"children":782},[],{"id":516,"text":517,"level":130,"children":784},[],{"id":520,"text":521,"level":130,"children":786},[],{"id":524,"text":525,"level":130,"children":788},[],{"id":528,"text":529,"level":130,"children":790},[],{"id":532,"text":533,"level":130,"children":792},[],{"id":536,"text":537,"level":130,"children":794},[],{"id":12,"title":796,"slug":797,"excerpt":798,"author":799,"categories":803,"featured_image":805,"reading_time_minutes":807,"meta_title":808,"meta_description":798,"og_image":5,"meta_robots":809,"schema_type":56,"faq_json":5,"video_url":5,"toc_json":810,"published_at":857,"updated_at":858},"How to Center a Div in CSS","how-to-center-a-div-in-css","A practical guide to how to center a div in CSS across real scenarios, from full-page layouts to modals, plus fixes for when it won't work.",{"slug":43,"display_name":44,"job_title":5,"short_bio":5,"expertise_tags":800,"headshot":5,"long_bio":5,"credentials":5,"twitter_url":5,"linkedin_url":5,"github_url":5,"personal_website_url":5,"other_sameas_urls":5,"topics":801,"posts":802},[],[],[],[804],{"name":9,"slug":10},{"url":806,"alt_text":5,"width":52,"height":53},"https:\u002F\u002Fwpfsharp.com\u002Fstorage\u002Fblog\u002Ffeatured\u002Fhow-to-center-a-div-in-css-v1.webp",8,"CSS Tutorials & Guides for Beginners | WPFSharp",[],[811,815,819,823,827,831,835,839,843,847,851,855],{"id":812,"text":813,"level":130,"children":814},"why-center-a-div-actually-means-four-different-things","Why \"Center a Div\" Actually Means Four Different Things",[],{"id":816,"text":817,"level":130,"children":818},"how-to-center-a-div-in-css-on-a-full-page-or-hero-section","How to Center a Div in CSS on a Full Page or Hero Section",[],{"id":820,"text":821,"level":130,"children":822},"keeping-an-element-centered-inside-an-existing-layout","Keeping an Element Centered Inside an Existing Layout",[],{"id":824,"text":825,"level":130,"children":826},"centering-with-css-grid-instead-of-flexbox","Centering With CSS Grid Instead of Flexbox",[],{"id":828,"text":829,"level":130,"children":830},"centering-a-modal-tooltip-or-overlay","Centering a Modal, Tooltip, or Overlay",[],{"id":832,"text":833,"level":130,"children":834},"the-text-align-trap-beginners-fall-into","The text-align Trap Beginners Fall Into",[],{"id":836,"text":837,"level":130,"children":838},"making-centered-layouts-actually-responsive","Making Centered Layouts Actually Responsive",[],{"id":840,"text":841,"level":130,"children":842},"troubleshooting-why-your-div-wont-center","Troubleshooting: Why Your Div Won't Center",[],{"id":844,"text":845,"level":130,"children":846},"quick-reference-which-method-fits-your-situation","Quick Reference: Which Method Fits Your Situation",[],{"id":848,"text":849,"level":130,"children":850},"mistakes-worth-avoiding","Mistakes Worth Avoiding",[],{"id":852,"text":853,"level":130,"children":854},"faq-about-centering-a-div-in-css","FAQ About Centering a Div in CSS",[],{"id":536,"text":537,"level":130,"children":856},[],"2026-09-07T16:53:48+00:00","2026-09-08T20:23:11+00:00",{"first":860,"last":860,"prev":5,"next":5},"http:\u002F\u002Fapp\u002Fapi\u002Fblog?page=1",{"current_page":12,"from":12,"last_page":12,"links":862,"path":871,"per_page":872,"to":112,"total":112},[863,866,869],{"url":5,"label":864,"page":5,"active":865},"&laquo; Previous",false,{"url":860,"label":867,"page":12,"active":868},"1",true,{"url":5,"label":870,"page":5,"active":865},"Next &raquo;","http:\u002F\u002Fapp\u002Fapi\u002Fblog",9]