There's no standard function for this, but you can define

bool prefix(const char *pre, const char *str)
{
    return strncmp(pre, str, strlen(pre)) == 0;
}

We don't have to worry about str being shorter than pre because according to the C standard (7.21.4.4/2):

The strncmp function compares not more than n characters (characters that follow a null character are not compared) from the array pointed to by s1 to the array pointed to by s2."

Answer from Fred Foo on Stack Overflow
🌐
GitHub
github.com › dotnet › runtime › issues › 78392
[Analyzer] Recommend string.StartsWith(c) instead of string.StartsWith("c") · Issue #78392 · dotnet/runtime
November 15, 2022 - using System.Globalization; CultureInfo.CurrentCulture = new CultureInfo("en-US"); Console.WriteLine("\u0061\u030a".StartsWith("\u00e5")); Console.WriteLine("\u0061\u030a".StartsWith('\u00e5')); It would be safe to replace string.StartsWith("c", StringComparison.Ordinal) with string.StartsWith('c') for arbitrary characters.
Author: dotnet
🌐
Reddit
reddit.com › r/c_programming › c programming startswith & endswith string functions
r/C_Programming on Reddit: C Programming startsWith & endsWith String Functions
April 16, 2022 - If the string fits in cache, most of the strlen calls would be more than an order of magnitude faster than the first one, but if the start of the string gets bumped from cache, then all calls could be slow. ... bool startsWith(const char* str, const char* prefix) { while (*prefix && *str == *prefix) ++str, ++prefix; return *prefix == 0; }
🌐
Codecademy
codecademy.com › docs › c# › strings › .startswith()
C# (C Sharp) | Strings | .StartsWith() | Codecademy
April 27, 2023 - Determines if the start of the string instance matches the specified string and returns a boolean.
🌐
myCompiler
mycompiler.io › view › J2AXVaEiMyB
String Starts With (C) - myCompiler
February 15, 2022 - Copy link Download · Share on Facebook Share on X (Twitter) Share on Reddit · Embed on website · Files · Files · #include <stdio.h> #include <stdbool.h> #include <string.h> bool StartsWith(const char *a, const char *b) { if(strncmp(a, b, strlen(b)) == 0) return 1; return 0; } int main() { printf("Hello world!\n"); if(StartsWith("/ngw/syspath-etc.clientlibs/emt/clientlibs/components/all/marketingsite.min.add284e2b278aa7db8424b941cfdb856.css", "/ngw")) { printf("Matched"); }else { printf("Not Matched"); } return 0; } Run Fork ·
Published: Feb 15, 2022
🌐
SysTutorials
systutorials.com › how-to-check-whether-a-string-starts-with-another-string-in-c
Checking If A String Starts With Another In C++ - SysTutorials
April 13, 2026 - Note: compare() safely handles edge cases where the prefix is longer than the string — it returns non-zero without undefined behavior. You can also use find() with position 0, though it’s less idiomatic: bool startswith(const std::string& str, const std::string& prefix) { return str.find(prefix) == 0; }
🌐
GitHub
github.com › portfoliocourses › c-example-code › blob › main › startswith.c
c-example-code/startswith.c at main · portfoliocourses/c-example-code
* Author: Kevin Browne @ https://portfoliocourses.com · * *******************************************************************************/ #include <stdio.h> #include <string.h> #include <stdbool.h> · bool startswith(char *string, char *start);  ...
Author: portfoliocourses
Find elsewhere
🌐
TutorialKart
tutorialkart.com › c-programming › c-program-check-if-string-starts-with-a-specific-substring
C Program - Check if String Starts with a Specific Substring
October 31, 2021 - In the following program, we take a string in str and substring in substr, take a for loop to iterate over characters of str and substr until the end of substr, and check if they are same. Refer C For Loop tutorial. ... #include <stdio.h> #include <stdbool.h> int main() { char str[30] = "apple banana"; char substr[30] = "app"; bool startsWith = false; for (int i = 0; substr[i] != '\0'; i++) { if (str[i] != substr[i]) { startsWith = false; break; } startsWith = true; } if (startsWith) { printf("String starts with specified substring.\n"); } else { printf("String does not start with specified substring.\n"); } return 0; }
🌐
R Package
rdrr.io › r › base › startsWith.html
startsWith: Does String Start or End With Another String?
grepl, substring; the partial string matching functions charmatch and pmatch solve a different task. startsWith(search(), "package:") # typically at least two FALSE, nowadays often three x1 <- c("Foobar", "bla bla", "something", "another", "blu", "brown", "blau blüht der Enzian")# non-ASCII x2 <- cbind( startsWith(x1, "b"), startsWith(x1, "bl"), startsWith(x1, "bla"), endsWith(x1, "n"), endsWith(x1, "an")) rownames(x2) <- x1; colnames(x2) <- c("b", "b1", "bla", "n", "an") x2 ## Non-equivalence in case of missing values in 'x', see Details: x <- c("all", "but", NA_character_) cbind(startsWith(x, "a"), substring(x, 1L, 1L) == "a", grepl("^a", x))
🌐
C++ Programming Language
cpp-lang.net › standard library › containers › strings › string › starts_with( )
std::string starts_with() method
#include <iostream> #include <string_view> #include <string> template <typename PrefixType> void test_prefix_print(const std::string& str, PrefixType prefix) { std::cout << '\'' << str << "' starts with '" << prefix << "': " << str.starts_with(prefix) << '\n'; } int main() { std::boolalpha(std::cout); auto helloWorld = std::string("hello world"); test_prefix_print(helloWorld, std::string_view("hello")); test_prefix_print(helloWorld, std::string_view("goodbye")); test_prefix_print(helloWorld, 'h'); test_prefix_print(helloWorld, 'x'); }
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › startsWith
String.prototype.startsWith() - JavaScript - MDN Web Docs
true if the given characters are found at the beginning of the string, including when searchString is an empty string; otherwise, false.
🌐
Elliana May
mause.me › blog › 2014 › 10 › 02 › c-string-startswith.html
C string startswith | Elliana May
October 1, 2014 - It gets the position of the needle in the haystack using strstr (who came up with that name, seriously), then, as strstr returns a pointer to the needle’s occurance in the string, we simply make sure that if it ain’t null, and that it’s equal to the original string.
🌐
C-sharptutorial
c-sharptutorial.com › string › startswith-in-csharp
C# StartsWith()
String.StartsWith() method is used to check if the string starts with a specified substring.
🌐
Cplusplus
cplusplus.com › forum › beginner › 85227
how to check if a string starts with a c - C++ Forum
November 17, 2012 - Well, you can either #1 find the substring (string::find) and, if it's there, check that it's at the beginning of the string #2 chop off the beginning of the string (string::substr) and then compare it against the expected value (== or string::compare) Andy
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.string.startswith
String.StartsWith Method (System) | Microsoft Learn
To determine whether a string begins with a particular substring by using the string comparison rules of the current culture, signal your intention explicitly by calling the StartsWith(String, StringComparison) method overload with a value of CurrentCulture for its comparisonType parameter.
🌐
Programiz
programiz.com › csharp-programming › library › string › startswith
C# String StartsWith() (With Examples)
Online Python Online JavaScript ... Rust Online Scala Online Dart Online R Online Ruby ... The String StartsWith() method checks whether the string starts with the specified string or not....
🌐
GeeksforGeeks
geeksforgeeks.org › c# › c-sharp-string-startswith-method
C# String StartsWith() Method - GeeksforGeeks
August 6, 2025 - Explanation: In this example, we use the StartsWith() method to check if the string is started with the HTML tag and if it returns true we remove that HTML tag.