Jump to content

Help With Strings.


Recommended Posts

I am opening a file and reading it, and I get this line from the file I am reading.:

^*^6fairplay ^Nchris ^&14:32:08 ^<demobase.eu

What I need is the charactor after the ^ only. (so the 6, N, &, < ) I don't want any other part of the string.

I've tried to split up this string but it is not really working. Are there any other methods to get the charactors after the ^

Link to comment
Share on other sites

local $string = "^*^6fairplay ^Nchris ^&14:32:08 ^<demobase.eu"

for $i = 0 to stringlen($string)
    if stringmid($string,$i,1) = "^" Then
        msgbox(64,"^", (stringmid($string, ($i + 1),1)))
    EndIf
Next

You can also do this by stringsplit on ^ into an array or stringinstr, stringbetween etc., but i like the more exotic ways :idea:

Edited by notsure
Link to comment
Share on other sites

It looks like you missed one in your expected results but we can fix that.

$sStr = "^*^6fairplay ^Nchris ^&14:32:08 ^<demobase.eu"
$aMatch = StringRegExp($sStr, "\^(.)", 3);; return a 0 based array of matching characters

If really dont want the * AND if that * is always in the same place change the second line to

$aMatch = StringRegExp($sStr, "\^(.)", 3, 2)
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks for all of the help but I'm having problems :/

This is the error I got when I tried to run my program.

Error: Subscript used with non-Array variable.

Func getColors()

FileGetTime("demo/MP/qconsole.log")
 If Not @error Then
 FileOpen("demo/MP/qconsole.log", 0)
 $line2 = FileReadLine($file, -1)
 $fairplayline = StringInStr($line2, "fairplay", 2)
 $fairplayline = ($fairplayline - 2)
 If $fairplayline > 1 Then
     If $fpcolor = stringmid($line2,$fairplayline,1) Then
    for $i = 0 to stringlen($line2)
    If  $fpcolor = "^" Then
        $fpcolor = stringmid($line2, ($fairplayline + 1),1)
    EndIf
Next
EndIf
    EndIf
EndIf
bind()
EndFunc

Little Help? :idea:

Edited by Mumms
Link to comment
Share on other sites

Your example doesn't contain any subscripts, so I guess the error is in a different part of the script. Best check the error line number.

My advise is to use the StringRegExp Geosoft gave you btw. It's less code, faster execution and with probably more reliable.

Link to comment
Share on other sites

for $i = 0 to stringlen($line)
    $getBadChar = stringmid($line,($fp + 4),$i)
    If $getBadChar = "e" or "^" or StringIsUpper($getBadChar) or StringIsDigit($getBadChar) Then
           ;This is where I want to get the postion of where the $getBadChar is so that I can get a string that starts at
           ; ($fp + 4) and ends at ($getBadChar - 1)
    EndIf

Any Help? :idea:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...