Sign in to follow this  
Followers 0
pintas

String problem (Again)

8 posts in this topic

#1 ·  Posted (edited)

Ok, here is my problem....

In the next file, i'm trying to get the strings client1; client2 and client3.

I'm putting the results in a combo box, but i don't want the repeated results, as you can see, if i pull the strings between the / and " i would have three client3 in the combo box

I would also like to capitalize the first letter of the results, but that would be a bonus. :huh2:

Can someone please help me on this? It's the very last thing i need to end this string nightmare.

Can i use an 'If' statement to sort this out?

Here is the file. I call it Config.php

<?php

    $folders = array(
        "1" => array("name" => "Name1", "path" => "/client1"),
        "2" => array("name" => "Name2", "path" => "/client2"),
        "3" => array("name" => "Name3", "path" => "/client3"),
        "4" => array("name" => "Name4", "path" => "/client3/access2"),
        "5" => array("name" => "Name5", "path" => "/client3/access3"),
    );
?>
Edited by pintas

Share this post


Link to post
Share on other sites



This may not be exactly what you are looking for, but maybe it will give you some ideas or point you in the right direction. Note that I put in the name Josh twice and it does not show up as a duplicate. This particular script assumes the client folder name will be consistently name. That is, client3/access2 will be always be named client3 and the subfolder can change. To make it work, I added a "Fluff" name to the end of the array so the loop count won't exceed its bounds.

Here's the code I played with:

#include <array.au3>
#include <string.au3>

Global $folders2[6]

Dim $folders[7][3] = [["Name1", "path", "/client"], ["John", "c:/path", "/John"], ["Josh", "c:/path", "/Josh"], ["Josh", "c:/path", "/Josh"], ["James", "c:/path", "/James"], ["Jake", "c:/path", "/Jake"], ["Fluff", "c:/path", "/Fluff"]]

$i = 0
Do
    $i = $i + 1
    If NOT StringInStr($folders[$i][2], $folders[$i + 1][2]) Then
        $folders2[$i] = $folders[$i][2]
    EndIf
Until $i = 5

_ArraySort($folders2, 1)

_ArrayDisplay($folders2)

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I see what you mean, but this script supposes that i can only have a limited number of strings (in this case 5 'Until $i = 5') and it seems that the 'client' is a fix value (["Name1", "path", "/client"]), witch is not the case.

I'm totally confused. Maybe i'm seeing it all wrong.

But i do appreciate your input. Thanks.

I'm playing with _StringBetween and stringtrimleft, stringtrimright, stringinstr, etc...

Edited by pintas

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I would also like to capitalize the first letter of the results, but that would be a bonus. :huh2:

#include <Array.au3>
Global $aArray[5] = ["eXample", "joHn", "jOS", "thediamond", "vergiE"]
_ArrayDisplay($aArray, "Before change")
For $1 = 0 To UBound($aArray) - 1
    $aArray[$1] = Proper($aArray[$1])
Next
_ArrayDisplay($aArray, "After change")
Func Proper($aString)
    $aChange = StringUpper(StringLeft($aString, 1)) & StringLower(StringRight($aString, StringLen($aString) - 1))
    Return $aChange
EndFunc   ;==>Proper

Propper spelling

Edited by JoHanatCent

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this:

#include <Array.au3>
#include <String.au3>

$sPHP = _
'<?php' & @LF & _
'    $folders = array(' & @LF & _
'       "1" => array("name" => "admin", "path" => "/damasco"),' & @LF & _
'        "2" => array("name" => "manager", "path" => "/rio"),' & @LF & _
'        "3" => array("name" => "microsoft", "path" => "/door/reports"),' & @LF & _
'        "4" => array("name" => "orange", "path" => "/door/financial"),' & @LF & _
'        "5" => array("name" => "carl", "path" => "/damasco/reports"),' & @LF & _
'    );' & @LF & _
'?>'
;~ $sPHP = FileRead("Config.php")

$aFilter = StringRegExp($sPHP, '(?U)"path" => "/(.*)\W', 3)
$aFilter = _ArrayUnique($aFilter)
_ArrayDelete($aFilter, 0)
_ArraySort($aFilter)
For $i = 0 To UBound($aFilter) - 1
    $aFilter[$i] = _StringProper($aFilter[$I])
Next
$sComboValue = _ArrayToString($aFilter)

$hGUI = GUICreate("Test", 300, 100)
$hCombo = GUICtrlCreateCombo("", 10, 10)
GUICtrlSetData(-1, $sComboValue, $aFilter[0])
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
Until $msg = -3
Exit

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks JoHanatCent, very nice. That's one problem solved. :huh2:

UEZ Thanks for your help. I've been trying to use StringRegExp but without success. But my problem remains. As i posted previously, the 'client' value isn't fixed, hence my difficulty. It could be anything really, like carrots to space shuttles. There are infinite possibilities, like in the example below, the file will grow daily, as it's for a client database.

This would mean that admin and carl would belong to the same company, or orange and microsoft, but they would have different usernames and different folder access.

<?php

    $folders = array(
        "1" => array("name" => "admin", "path" => "/damasco"),
        "2" => array("name" => "manager", "path" => "/rio"),
        "3" => array("name" => "microsoft", "path" => "/door/reports"),
        "4" => array("name" => "orange", "path" => "/door/financial"),
        "5" => array("name" => "carl", "path" => "/damasco/reports"),
    );
?>
Edited by pintas

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I updated the code from post #5.

Does this fit to your needs?

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I updated the code from post #5.

Does this fit to your needs?

Br,

UEZ

WOW!

So, i guess you really solved all of my problems... :huh2:

Thanks alot man! This is just perfect!

That StringRegExp is still very confusing to me, and i didn't had a clue that _ArrayUnique even existed. I'll explore those options to see if i can learn from them.

Again.... Thank you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0