ID:132863
 
It would be pretty nifty if you could get findtext to search backwards, I could simulate that myself by reversing the string but a built in feature would be nice :)
Wah? So you could search for "olleh" in "hello" and it would find it? Purpose?
In response to Falacy
Falacy wrote:
Wah? So you could search for "olleh" in "hello" and it would find it? Purpose?

Not exactly.

Here's an example, to get the extension name of a file I have to do this, currently:

/*
This procedure takes a string as an argument and returns the string in reversed format

For example: StringReverse("hello") would return "olleh"
*/


StringReverse(string)
.=""
for(var/i=length(string);i>0;i--)
.+=copytext(string, i, i+1)

/*
This procdure takes a string (filename) as an argument and returns the extension of the file
*/


GetExtension(string)
if(findtext(string, "."))
. = copytext(string, GetLastInstance(string, "."))

/*
This procedure returns the position of the last instance of 'instanceOf'
*/


GetLastInstance(string, instanceOf)
. = (length(string)+1) - findtext(StringReverse(string), instanceOf)


When with this new feature I could do this:

proc

GetExtension(string)
. = findtext(string, ".", 0, 1) //0 - so start at the end and 1 to finish at the start (going backwards)
. = copytext(string, .)


See a benefit?
In response to Haywire
Haywire wrote:
Here's an example, to get the extension name of a file I have to do this, currently:

or you could just do one of these:
copytext(FileName,findtext(FileName,"."),0)
copytext(FileName,length(FileName)-3,0)


See a benefit?

Not so much in that scenario =P
In response to Falacy
Falacy wrote:
Haywire wrote:
Here's an example, to get the extension name of a file I have to do this, currently:

or you could just do one of these:
> copytext(String,findtext(String,"."),0)
> copytext(String,length(String)-3,0)
>

See a benefit?

Not so much in that scenario =P

Firstly, an extension can be more than 3 characters and secondly a file name could consist of more than 1 dot, for example (lol.lol.lol.txt), with your method I would get (lol.lol.txt), I want (.txt)
In response to Haywire
[link]

Second point made by Hiead.
In response to Haywire
Since string manipulation isn't really one of BYOND's strong points, I don't think implementing this as a hard-coded solution would garner much gain.
In response to Metamorphman
If something isn't your strong point wouldn't you work on it?

That makes sense.
In response to Haywire
This isn't going to make BYOND's string manipulation any faster as a whole, but it will make it easier to use. When I say string manipulation isn't a strong point, I mean that its not going to be so much of a gain when you can use a hard-coded method to gain what, like 0.01 second on the soft-coded method.

For a good feature, a mixture of efficiency, speed and ease of use are needed, and this feature isn't pretty light on 2/3 of those parts.
In response to Haywire
You deleted the thing I was about to reply to <.< anyway:
proc/ReverseFindText(Whole,Part)
if(findtext(Whole,Part))
for(var/i=length(Whole)-length(Part)+1; i>0; i--)
if(findtext(Whole,Part,i)) return i

mob/verb/FindExt()
var/FileName="You.Fail.At.Naming.Files.EpicFail"
world<<copytext(FileName,ReverseFindText(FileName,"."))
In response to Falacy
Falacy wrote:
You deleted the thing I was about to reply to <.< anyway:
> proc/ReverseFindText(Whole,Part)
> if(findtext(Whole,Part))
> for(var/i=length(Whole)-length(Part)+1; i>0; i--)
> if(findtext(Whole,Part,i)) return i
>
> mob/verb/FindExt()
> var/FileName="You.Fail.At.Naming.Files.EpicFail"
> world<<copytext(FileName,ReverseFindText(FileName,"."))
>


Yes, what about that?
In response to Haywire
Haywire wrote:
Yes, what about that?

There's your <s>reverse</s> backwards searching findtext() proc, shuffle along =P
In response to Falacy
Falacy wrote:
Haywire wrote:
Yes, what about that?

There's your reverse findtext() proc, shuffle along =P

That wasn't my point, yes, a soft-coded version could be implemented like you and I just did, I'm just asking for a hard-code version, it seems you are against this though :S
In response to Haywire
Haywire wrote:
That wasn't my point, yes, a soft-coded version could be implemented like you and I just did, I'm just asking for a hard-code version, it seems you are against this though :S

Meh, not really, just not really for it either =P
Since as you said, we can easily make the procs ourselves, why bother having them do it?
In response to Falacy
Falacy wrote:
Haywire wrote:
That wasn't my point, yes, a soft-coded version could be implemented like you and I just did, I'm just asking for a hard-code version, it seems you are against this though :S

Meh, not really, just not really for it either =P
Since as you said, we can easily make the procs ourselves, why bother having them do it?

A lot of features can be written ourselves, what's the point of them?

I'll tell you, it's easier to do something, it's pretty much more convenient, this isn't a must-feature, but it'd be pretty cool to have it, simple.
In response to Haywire
Haywire wrote:
A lot of features can be written ourselves, what's the point of them?
I'll tell you, it's easier to do something, it's pretty much more convenient, this isn't a must-feature, but it'd be pretty cool to have it, simple.

Welp, I wrote one, just copy and paste it into your project and it'll do what theirs would, with no real effort from you =P
And no, most features shouldn't be things we can do ourselves. Feature requests should be reserved for things that are either entirely impossible, or are so complicated/inefficient to do on our own that's its not even wroth the effort, but that would be simple (or at least simpler) for them to implement. They should also have a vast amount of practical uses, that would effect a large portion of the dev community, which this one would at least meet that requirement.
In response to Haywire
Remember some files don't have an extension too :p
In response to Chowder
Chowder wrote:
Remember some files don't have an extension too :p

if(findtext(fname, "."))
In response to Haywire
Err..Right, Good job o.o