Author Topic: Function to check if SlickC string variable has a substring?  (Read 904 times)

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Function to check if SlickC string variable has a substring?
« on: January 17, 2022, 06:38:33 PM »
Is there a SlickC function that returns if a SlickC string contains a particular substring?

For example lets say:

Code: [Select]
_str fullString="hello world";
containsSubstring1 = some_match_function(fullString, "world");
if (containsSubstring1)
{
  // Should end up here because 'world' is in 'hello world'
}
else
{
  // Should not end up here because 'world' is in 'hello world'
}
containsSubstring2 = some_match_function(fullString, "abc123");
if (containsSubstring2)
{
  // Should NOT end up here because 'abc123' is not in 'hello world'
}
else
{
  // Should end up here because 'abc123' is not in 'hello world'
}

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: Function to check if SlickC string variable has a substring?
« Reply #1 on: January 17, 2022, 06:41:47 PM »
I think I found it, the pos() function?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Function to check if SlickC string variable has a substring?
« Reply #2 on: January 17, 2022, 08:02:47 PM »
Yes, pos() does what you need

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Function to check if SlickC string variable has a substring?
« Reply #3 on: January 18, 2022, 12:06:04 AM »
I should mention that beginsWith() and endsWith() are also very handy for string matching.