PDA

View Full Version : String Trimming


Bruce
01-01-2004, 07:13 PM
After finding all my folders using the code below:

result = Folder.Find("AutoPlay\\Plugins", "*", false, nil);
for index,folder in result do
folders = ListBox.AddItem("plugs list", folder, folder);
end

(Thanks Corey)

The information is placed into a ListBox as follows:

AutoPlay\Plugins\ Folder 1
AutoPlay\Plugins\ Folder 2
AutoPlay\Plugins\ Folder 3

I would like to show ONLY the name of the folder it’s self, like this:

Folder 1
Folder 2
Folder 3

So… I thought using a String.Replace would do the trick but… Again I’m not getting the right combinations. I tried this:

result = Folder.Find("AutoPlay\\Plugins", "*", false, nil);
for index,folder in result do
result = String.Replace("AutoPlay/Plugs/", "AutoPlay", "", false);
ListBox.AddItem("plugs list", folder, folder);
end

But it didn’t work. Perhaps using the variable “result”…
result = String.Replace("result", "AutoPlay", "", false); NOPE!

What the heqq is the magic combo? I looked through the help files but I didn’t quite get what I was looking for or didn’t understand perhaps the obvious.

element78
01-01-2004, 07:45 PM
I didn't feel like completely recreating the situation, because of the length of time it would take, but possibly you can try something like this:

pathsplit = String.SplitPath("AutoPlay\\Plugins\\Folder1");
totalchars = String.Length(pathsplit[2]);
trimposition = String.ReverseFind(pathsplit[2], "\\\", false);
trimthis = totalchars - trimposition;
finaloutput = String.TrimLeft(pathsplit[2], trimthis);
-- finaloutput should be Folder1


there's most likely a hundred syntax errors in that, I was just doing a quicky job on it so you can get the jist of the method I'm trying to describe.

Hope this helps a little.

-Adam

Bruce
01-01-2004, 08:09 PM
Thx element78-
LOL there MUST be an easier way! I seem to remember Tigg having done this before.

element78
01-01-2004, 08:13 PM
lol, you're probably right. But that's just the first thing that came to mind :)

Bruce
01-03-2004, 01:40 PM
Does anyone know of an easier way?

Stefan_M
01-03-2004, 04:11 PM
Hi,

I'm working with string replacement and it works for me


_Searchdir=_SourceFolder.."\\Autoplay\\Plugins";
FolderList = Folder.Find(_Searchdir.."\\", "*", false, nil);
for j in FolderList do
FolderName= String.Replace(FolderList[j], _Searchdir.."\\", "", false);
--add the item to the listbox, with the name visible and path as data
ListBox.AddItem("ListBox1", FolderName,FolderList[j]);
end





hope it helps

Stefan

Bruce
01-03-2004, 07:50 PM
Thx Stefan!
Looks like it's longer then I had hoped, oh well, kick-in and screaming the whole way! LOL