What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Several Questions...

Pages: (2): « First [ 1 ] 2 » Last »
Several Questions...
Author: Message:
Robin4286
Junior Member
**


Posts: 21
Joined: Sep 2006
O.P. Several Questions...
Okay, so I have a few questions about scripting in plus

1. Can you read/write to a file? If so, how?

2. Can you have it search for a phrase in that file? If not, an alternate method to find a keyword?

3. Can you do substrings? If so, how?

Thanks in advance!
09-15-2006 10:39 PM
Profile E-Mail PM Find Quote Report
cloudhunter
Senior Member
****


Posts: 536
Reputation: 18
37 / – / –
Joined: Dec 2005
RE: Several Questions...
quote:
Originally posted by Robin4286
Okay, so I have a few questions about scripting in plus

1. Can you read/write to a file? If so, how?

Yes, search the forums.
quote:
2. Can you have it search for a phrase in that file? If not, an alternate method to find a keyword?

Again, search.
quote:
3. Can you do substrings? If so, how?

What do you mean by substrings?

Cloudy
[Image: cloudy.jpg]
Sig by pirateok/marisaok/marisa ;)
quote:
Originally posted by Moulin Rouge
The greatest thing you'll ever learn, is just to love and be loved in return

6910 days, 22 hours, 50 minutes, 22 seconds ago
09-15-2006 10:44 PM
Profile E-Mail PM Find Quote Report
Robin4286
Junior Member
**


Posts: 21
Joined: Sep 2006
O.P. RE: Several Questions...
Okay, so i found the reading/writing post

Could you be a bit more specific on what i need to search for for the finding a string in a file?

and substrings are pieces of strings, like in java saying (string).subStr(2,3) starts at the second digit, counts three forwards, then returns that selection

12345
hello

could i just get the 'ell' from it?
09-15-2006 11:04 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: Several Questions...
Yes, you can use substrings and I think it's the same syntax... For finding a word in a file, I would use something like

code:
var myString = TextFromFile //contains text from file

myString = myString.split(" ");
for(var i=0;i<=myString.length;i++){
if(myString[i]==KeyWord){
//Code
}
}


There is probably an easier, more correct way to do this though :p
<Eljay> "Problems encountered: shit blew up" :zippy:
09-15-2006 11:08 PM
Profile PM Find Quote Report
Huhu_Manix
Full Member
***

Avatar
Upload me again... *salivate*

Posts: 106
– / Male / –
Joined: Jul 2006
RE: Several Questions...
You can use indexOf() for find a word too.

And for the substring, the good syntax is :
code:
var a = "abc";
var b = a.substring(1);
09-15-2006 11:24 PM
Profile E-Mail PM Web Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: Several Questions...
SpunkyLoveMuff's method may work in some cases, but there is an easier and sometimes better way to do it.
code:
// In this example, the variable sFile contains all the text from the file you read.
var sSearch = "Is this in the file?"; // The variable contains what you are searching for.
var nIndex = sFile.indexOf(sSearch); // Find the index that this phrase is located.
if(nIndex > -1){ // String.indexOf returns -1 if the string is not found
// nIndex is the position (an integer) that represents where the first character is. It is zero-based.
var nEndIndex = nIndex + sSearch.length - 1; // The variable nEndIndex represents the index that the phrase ends on.
// Do whatever you want
} else { // If the index is -1, the phrase not found
// Do whatever
}

Also, Huhu_Manix's code will not give you what you want. His code will give you "bc", it cuts off the first letter. If you want the second, third, and fourth letter of a string, use this:
code:
var sString = "hello"; // The string to extract from.
var sSubString = sString.substr(1,3); // The first parameter is the index to start at. It is zero-based. The second is how many characters to include. If you leave out the second, it will just cut off however many characters you specify in the first parameter.

This post was edited on 09-15-2006 at 11:33 PM by deAd.
09-15-2006 11:28 PM
Profile PM Find Quote Report
Huhu_Manix
Full Member
***

Avatar
Upload me again... *salivate*

Posts: 106
– / Male / –
Joined: Jul 2006
RE: Several Questions...
I give him only the good syntax of substring...

But ".substr()" work too ? ^o)

This post was edited on 09-15-2006 at 11:40 PM by Huhu_Manix.
09-15-2006 11:39 PM
Profile E-Mail PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Several Questions...
This should really help you with your scripting and understand what can be done using JScript.
[Image: markee.png]
09-16-2006 07:09 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Several Questions...
quote:
Originally posted by Huhu_Manix
You can use indexOf() for find a word too.

And for the substring, the good syntax is :
code:
var a = "abc";
var b = a.substring(1);

(...)

I give him only the good syntax of substring...

But ".substr()" work too ? ^o)
There is no 'good' and 'wrong' syntax.

substr and substring are two different functions. They do not work the same way. Each has his own specific uses.

quote:
Originally posted by deAd
code:
var sSubString = sString.substr(1,3); // The first parameter is the index to start at. It is zero-based. The second is how many characters to include. If you leave out the second, it will just cut off however many characters you specify in the first parameter.

nope... leaving out the second parameter will not cut off anything; it will return the remainder of the whole string.


-------------------------

Syntax: stringvar.substr(start [, length ])
  • stringvar
    Required.
    A string literal or String object from which the substring is extracted.

  • start
    Required.
    The zero-based starting position of the desired substring.

  • length
    Optional.
    The number of characters to include in the returned substring.

    If zero or negative, an empty string is returned.
    If not specified, the substring continues to the end of stringvar.

  • Example
    var s = "The rain in Spain falls mainly in the plain.";
    return s.substr(12, 5); // Returns "Spain".
    return s.substr(24);     // Returns "mainly in the plain.".

Syntax: stringvar.substring(start, end)
  • stringvar
    Required.
    A string literal or String object from which the substring is extracted.

  • start
    Required.
    The zero-based starting position of the desired substring.

  • end
    Required.
    The zero-based position indicating the end of the substring.

  • Remarks
    The substring method returns a string containing the substring from start up to, but not including, end.

    The substring method uses the lowest value of start and end as the beginning point of the substring. For example, strvar.substring(0, 3) and strvar.substring(3, 0) return the same substring.

    If either start or end is NaN or negative, it is replaced with zero.

    The length of the substring is equal to the absolute value of the difference between start and end. For example, the length of the substring returned in strvar.substring(0, 3) and strvar.substring(3, 0) is 3.

  • Example
    var s = "The rain in Spain falls mainly in the plain..";
    return s.substring(12, 17); // Returns "Spain".
    return s.substring(17, 12); // Returns "Spain".
    return s.substring(-10, 3); // Returns "The".


---------

In this post, you can see the 3 practical and different examples of the different uses:
CookieRevised's reply to "[I help them] VB2JS":
quote:
Snippet from original posting from CookieRevised
// Returns a string containing a specified number of characters from the left side of a string.
function Left(s, length) { return s.substring(0, length) }

// Returns a string containing a specified number of characters from the right side of a string.
function Right(s, length) { return s.substr(s.length-length) }

// Returns a string containing a specified number of characters from a string (length parameter is optional).
function Mid(s, start, length) { return s.substr(--start, length) }
Left() uses the substring method
Right() uses the substr method
Mid() uses the substr method with optional length parameter.






This post was edited on 09-17-2006 at 01:51 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-17-2006 01:29 AM
Profile PM Find Quote Report
Huhu_Manix
Full Member
***

Avatar
Upload me again... *salivate*

Posts: 106
– / Male / –
Joined: Jul 2006
RE: RE: Several Questions...
quote:
Originally posted by CookieRevised
There is no 'good' and 'wrong' syntax.

There is 'good' and 'wrong' syntax.
code:
var gnu = "abc";
var gna = gnu.sUbStriNg(1, 2); // Wrong syntax
var gnb = gnu.substring(1, 2); // Good syntax

:)

This post was edited on 09-17-2006 at 12:38 PM by Huhu_Manix.
09-17-2006 12:37 PM
Profile E-Mail PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On