Author Topic: working with idStrg class  (Read 271 times)

0 Members and 1 Guest are viewing this topic.

argoon

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
working with idStrg class
« on: August 27, 2017, 04:32:26 PM »
Hello guys and gals :)

I need help from some idtech 4 coder that has experience working with the idStrg class, it has many functions ( or members )  to mess around with, but because i don't know what half of them do i'm really going blind here, what i'm trying to do is take a file path, like a icon path, get a particular string from it (like a file name) compared that to some other string and if true or false run some code. Anyone here know anything about this? 

Phrozo

  • Mr. Phrozo
  • Jr. Member
  • **
  • Posts: 89
  • Karma: +15/-1
  • :3
    • View Profile
    • Mod Page
Re: working with idStrg class
« Reply #1 on: August 27, 2017, 10:48:28 PM »
I don't have much experience with the idStr class but from what I can see you could try something like this.
Code: [Select]
    idStr filePath  = "C:/Doom3/mod_folder/icon.ico";
idStr compareTo = "icon.ico";
idStr fileName;

filePath.ExtractFileName( fileName );

if ( fileName == compareTo ) {
        // icon file found
  } else {
      // icon file not found!
  }

Sorry about the code formatting.

argoon

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
Re: working with idStrg class
« Reply #2 on: August 28, 2017, 07:50:10 AM »
I don't have much experience with the idStr class but from what I can see you could try something like this.
Code: [Select]
    idStr filePath  = "C:/Doom3/mod_folder/icon.ico";
idStr compareTo = "icon.ico";
idStr fileName;

filePath.ExtractFileName( fileName );

if ( fileName == compareTo ) {
        // icon file found
  } else {
      // icon file not found!
  }

Sorry about the code formatting.

Thank you that helped. :)

No need to ask for sorry about that, i'm still learning to code so my code is pretty much a mess, i'm sure that one year from now i will look back and say, how dumb i was! :D


I also found out after your help that you can also remove the path and the extension from a file name very easily, in that way you also end with just the desired string:

Example:
Code: [Select]
idStr iconType;

iconType = item->GetString("inv_icon"); // "guis/assets/pda/inventory/inventory_battery.tga"
iconType.StripPath(); // inventory_battery.tga
iconType.StripFileExtension(); // inventory_battery
« Last Edit: August 28, 2017, 07:54:27 AM by argoon »