Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. substring in a std::string

substring in a std::string

Scheduled Pinned Locked Moved C / C++ / MFC
xmltutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahultaing
    wrote on last edited by
    #1

    can anyone tell me how to check whether a particular substring is present in a given string or not? I have a string containing file name and I have to check whether the file is an xml file or not. So I have to look for ".xml" substring in that given string. How do we do that?

    S 1 Reply Last reply
    0
    • R rahultaing

      can anyone tell me how to check whether a particular substring is present in a given string or not? I have a string containing file name and I have to check whether the file is an xml file or not. So I have to look for ".xml" substring in that given string. How do we do that?

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      Try something like this. NOTE: I haven't tested this so your mileage may vary: ---------------- string::size_type LastDotPos = YourString.find_last_of('.'); if ( LastDotPos != -1 ) { string Extension = YourString.substr(LastDotPos); transform(Extension.begin(), Extension.end(), Extension.begin(), ::tolower); if ( Extension == ".xml" ) { // Ends in ".xml". } } Steve

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups