[SOLVED] Filter spaces from data into array from text file

  • Hello,

    I am trying to load usernames and passwords from a text file into an array.

    All seems to work fine except I want it to ignore spaces and returns (enters).

    I ask this because when I put some names and passwords in the text file like this:

    FirstnameLastname|password;FirstnameLastname|password;FirstnameLastname|password;

    I can get it to work just fine.

    But when i do this;

    Firstname Lastname|password;

    Firstname Lastname|password;

    Firstname Lastname|password;

    it seems to mess up.

    Obviously the second option would be a lot easier to read though so I would like it to filter out the spaces and returns when putting it into the array.

    Thanks for reading,

    Danny

  • I would first try if replace(string, " ", "") works for this..

  • Where do I put that?

    Currently putting data into the array with:

    Set value at (i, 0) to tokenat(AJAX.LastData,i,";")

    In a 'for' loop of course..

  • this is for website? I means, the text is saved in a server and you need to be connect in internet?

    You can save a full array in a a .json file and just load when you need it...

    If your project is working online, I suggest you to make a database and don't use any text file

  • If you'd like to implement it in that action it should be something like:

    tokenat(replace(AJAX.LastData, " ", ""),i,";")

    But to make sure it works, you might just want to try setting two text objects;

    one to : replace(AJAX.LastData, " ", "")

    and one to : AJAX.LastData

    to check if the idea actually has the effect I believe it should..

  • Yes Ribis it is for a website and meant to be used online. I just stuck to a text file because someone else that never uses Construct2 has to be able to add users and passwords.

    I don't have knowledge on how to make databases..

    Thank you both for responding.

  • If someone else has to do it, you might want to look into the CSV - to array plugin.

    It takes normal csv files and automatically loads them into an array.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes Ribis it is for a website and meant to be used online. I just stuck to a text file because someone else that never uses Construct2 has to be able to add users and passwords.

    I don't have knowledge on how to make databases..

    Thank you both for responding.

    in this case, I really suggest you to use a database, put everything is a text file can be easily hacked and people can see all of the password in the array...

    how you check if the password is correct in construct2? you have to load all of the user/password in the project... if someone check what the website load (in the Console Javascript of Chrome for example) everybody can see the password of all of the users... same for the array...

    make a database is very easy, if you try to find "how to make login/registration in php" you can see how easy is to make a database with the php files... contruct2 have to send just data (with the POST method) the username and the password in a php file...

  • Again thank you both for being so helpfull.

    I am not going to risk it and go for a database then. I can learn it I am sure. *fist in the air*

  • Again thank you both for being so helpfull.

    I am not going to risk it and go for a database then. I can learn it I am sure. *fist in the air*

    Shake that fist

    tip: for windows, download WAMP. (Windows Apache MySQL PHP)

    Its a total package giving you a webserver with PHP support and a database server based on MySQL. Which you run locally on your computer/laptop. You use this in conjunction with Ajax requests.

    ie

    Ajax request requests url to a PHP file, the PHP file process the request to update or add or extract from the database, and echoes back the info in the Ajax request (Ajax.LastData)

    The database has a webinterface called phpmyadmin ... very easily to understand if you are relatively new to the whole databases concept.

    Zillions of posts all over the internet with tips/suggestions/advice to nearly anything with it.

    And its free

  • I do actually have some webspace so i should already have everything you just mentioned except for testing i guess doing it offline would be handy. Saves me uploading every itteration right?

    I am currently trying to follow this tutorial https://www.scirra.com/tutorials/525/si ... l-database

    I understand the php bit and the construct2 bit but just not sure about the phpmyadmin bit which i did locate on my webhost dashboard. The very first code in the tutorial is giving me the most headscratching. Not giving up though *shakes head*

    Thanks for the advice!

  • Yeah that first bit is actually plain mysql code.

    In phpmyadmin there would be a box to paste that in and execute plain mysql code.

    .

    Paste it in the text box, and hit execute

  • 'GO' in my case whehehe cheers

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)