Author Topic: Detecting if a substring is in a particular string  (Read 483 times)

flethuseo

  • Senior Community Member
  • Posts: 176
  • Hero Points: 2
Detecting if a substring is in a particular string
« on: February 12, 2018, 11:42:26 pm »
Good day,

I'm trying check if a path has the following string:
Code: [Select]
    "lin64vm458"

For example the function would return true for the following path:
Code: [Select]
    "C:\tibco\lin64vm200\lin64vm458\abc\defg\"

Is there a builtin function I can use for this? Or does anyone have a
snippet that returns true if it has that string?


I have set up mirror folders between a unix and windows machine and I'm trying to build
the unix path based on its windows equivalent, this is what I have so far. If anyone
knows a better way to do this at least for joining the paths.. let me know


Code: [Select]
    _command void copy_unix_path() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
    {
    _str machineName, unixHome;
    int status = LoadRsyncIniFile(machineName, unixHome);

    /* Get the directory name and file name */
    _str dirName = _strip_filename(p_buf_name,'N');
    _str filName = _strip_filename(p_buf_name,'P');

    _str windHome = 'C:\' :+ machineName :+ '\qa\';
    _str relaPath = substr(dirName, windHome._length());
    relaPath = stranslate(relaPath, '/',   '\');
    _str fullPath = unixHome :+ relaPath;

    _copy_text_to_clipboard(fullPath :+ filName);
    // _copy_text_to_clipboard(_strip_filename(p_buf_name,'PE'));
    }

Thanks,
Ted
« Last Edit: February 12, 2018, 11:44:56 pm by flethuseo »

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2364
  • Hero Points: 319
Re: Detecting if a substring is in a particular string
« Reply #1 on: February 28, 2018, 10:56:20 pm »
Check out the Slick-C pos() function.

If you really want to be thorough, use it in combination with _file_case().
Code: [Select]
    p := pos(_file_case("lin64vm458"), _file_case(fullPath));
    haveSubstring := ( p > 0 );