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

flethuseo

  • Senior Community Member
  • Posts: 177
  • 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

  • Senior Community Member
  • Posts: 3955
  • Hero Points: 515
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 );