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

Get help using Construct 2

Post » Sat Apr 18, 2015 8:18 am

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
Last edited by UberDark on Sun Apr 26, 2015 5:41 pm, edited 1 time in total.
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Sat Apr 18, 2015 8:28 am

I would first try if replace(string, " ", "") works for this..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Apr 18, 2015 8:32 am

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..
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Sat Apr 18, 2015 8:42 am

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
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Sat Apr 18, 2015 8:44 am

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Apr 18, 2015 8:48 am

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.
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Sat Apr 18, 2015 8:52 am

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.

plugin-csv-csv2array-csv2dictionary_t64326?&hilit=csv
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Apr 18, 2015 8:58 am

UberDark wrote: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...
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Sat Apr 18, 2015 9:23 am

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*
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Sat Apr 18, 2015 9:33 am

UberDark wrote: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 :D


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 :)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Next

Return to How do I....?

Who is online

Users browsing this forum: jorgmaquoi, Sup with that? and 58 guests