Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Find word in .txt file

rolevix
Registered User
Quote
2018-12-09 07:49:08

Hello, wizards!

Is there anybody know JS script in CCB to find specific word in .txt file?
And if this word is present in the .txt file => do something

For example, i just need to make LOGIN system.

User will enter Login, and if this login is present in .txt file from my server => he must enter password, password is next string in .txt => if login and password correct => also read from this file next strings, like "money", "level" => just change scene => play with variables from your account


Aiming_bullets
Guest
Quote
2018-12-09 07:57:13

There is already a plugin by @Just_in_case is available to download which reads a single line of string from a text file.

You can download the plugin from ambiera's extensions page.

Hope that helps.


Aiming_bullets
Guest
Quote
2018-12-09 07:59:26

In addition to my previous post there is also a simple login and signup example provided by the same guy named as @Just_in_case is available on the forums all you have to do is to crawl the forums


Aiming_bullets
Guest
Quote
2018-12-09 08:02:09

Here is the link to login and signup example

https://www.ambiera.com/forum.ph...


rolevix
Registered User
Quote
2018-12-09 08:51:27

Thanks for answer :)

But that is not what im looking for.

I need script or plugin to FIND SPECIFIC WORD in .txt file




tim12345
Guest
Quote
2018-12-09 11:52:52

intriguing question... behold my attempt to solve part of the riddle using string match method!
var FileName= "datafile.txt"
var WordToSearch= "LoginName"

var str = ccbReadFileContent(FileName);
var result = str.match(WordToSearch);

if(result== WordToSearch){
print("Word Found!");
}

if(result!= WordToSearch){
print("Word NOT Found!");
}

maybe that method could be useful for you.


rolevix
Registered User
Quote
2018-12-09 18:18:10

Thank you tim12345!

This is almost what i mean!

But... this script is read isn't full word as correct...

For example:

When login word is "USER"
it accept this as correct

But even i type "USE","US" or "U"
It also accept this as correct

This is strange

Can you fix this? Please


tim12345
Guest
Quote
2018-12-09 18:51:19

hm... this seems to be more complex than I originally thought!
what if you were to encase the LoginName in the .txt file with say an x, like so:

xLoginNamex


then we modify the script a bit...

var FileName= "datafile.txt"
var WordToSearch= "x"+"LoginName"+"x";

var str = ccbReadFileContent(FileName);
var result = str.match(WordToSearch);

if(result== WordToSearch){
print("Word Found!");
}

if(result!= WordToSearch){
print("Word NOT Found!");
}

would that fix it?


rolevix
Registered User
Quote
2018-12-09 20:41:57

Nope...

For now it just accept all words as correct

Im not a programmer, for me its look like a magic


tim12345
Guest
Quote
2018-12-10 01:18:11

ah darn! it seems to work for me.

oh well, i tried! hopefully someone knows of a better way.


xanimalkingx
Registered User
Quote
2018-12-10 05:48:46

I can make a small extension that can search for a specific word in a file so you can use it as a coppercube extension, for those who are uncomfortable with programming, However, it will be put on the backburner because I am developing my own extension right now. Its on my todo list, though. So, don't worry about not finding a solution.


rolevix
Registered User
Quote
2018-12-10 08:56:54

@tim12345 - Anyway, thank you for trying

@xanimalkingx - I would be very grateful, at the moment I am also busy with my project, I think I can postpone this part of the project for a while!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Interna?ional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact