News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

working with idStrg class

Started by argoon, August 27, 2017, 04:32:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

argoon

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

I don't have much experience with the idStr class but from what I can see you could try something like this.

    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

#2
Quote from: Phrozo 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.

    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:

idStr iconType;

iconType = item->GetString("inv_icon"); // "guis/assets/pda/inventory/inventory_battery.tga"
iconType.StripPath(); // inventory_battery.tga
iconType.StripFileExtension(); // inventory_battery