Raised This Month: $ Target: $400
 0% 

Cutting Folder from a String


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-08-2013 , 13:18   Cutting Folder from a String
Reply With Quote #1

Hey everybody,

For my plugin I need to cut-off the folder of a string to create it if it doesn't exist, but I couldn't find any existing method to do that. Anyone has an Idea how to do that?

String Format (Examples) :

Quote:
maps/de_tuscan.bsp
models/de_tuscan/tuscan_grass1a.mdl
gfx/env/dustup.tga
What I need:

Quote:
maps
models/de_tuscan
gfx/env
__________________

Last edited by Kia; 09-08-2013 at 13:28.
Kia is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 09-08-2013 , 14:33   Re: Cutting Folder from a String
Reply With Quote #2

Why don;t you use replace and then check if altered string is a valid folder?
Clauu is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-08-2013 , 14:52   Re: Cutting Folder from a String
Reply With Quote #3

What do you want to replace?
__________________
Kia is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-08-2013 , 15:04   Re: Cutting Folder from a String
Reply With Quote #4

You could iterate backward through the string and when you find the '/', replace it with a 0.
__________________
fysiks is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-08-2013 , 15:15   Re: Cutting Folder from a String
Reply With Quote #5

How do I that backward?
__________________
Kia is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-08-2013 , 15:17   Re: Cutting Folder from a String
Reply With Quote #6

Quote:
Originally Posted by Kia View Post
How do I that backward?
Start at strlen() and in your for loop, do i-- for the incrementer. When you find the '/' set it to 0 then break.
__________________
fysiks is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 09-08-2013 , 15:35   Re: Cutting Folder from a String
Reply With Quote #7

Quote:
Originally Posted by Kia View Post
What do you want to replace?
replace("maps/de_tuscan.bsp",len,"de_tuscan.bsp","")

Last edited by Clauu; 09-08-2013 at 15:35.
Clauu is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-08-2013 , 15:51   Re: Cutting Folder from a String
Reply With Quote #8

It's not always the same string, I was giving an example only.
__________________
Kia is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-08-2013 , 15:51   Re: Cutting Folder from a String
Reply With Quote #9

Quote:
Originally Posted by Clauu View Post
replace("maps/de_tuscan.bsp",len,"de_tuscan.bsp","")
That requires you to know the filename which makes this approach not very useful.
__________________
fysiks is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 09-08-2013 , 16:13   Re: Cutting Folder from a String
Reply With Quote #10

Well then as it been said you could iterate bacward because starting from the end you will have less to count.
As a ideea when you hit the first '/' from the end then stop and replace the iterator position with a null terminated char then copyc until you find that null char, or use that position and make a strmid function something like substr.

Last edited by Clauu; 09-08-2013 at 16:14.
Clauu is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode