Jump to content

Something like len


Azu
 Share

Recommended Posts

  • Moderators

Except to count the amount of words or whatever (separated by second)

Is there a function already in existence that does something like this? Or will I have to make my own using stringsplit and stuff?

:P

:nuke:

Huh???

Can you give an example of the string?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

StringLen

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

Returns the number of characters in a string.

StringLen ( "string" )

Parameters

string The string to evaluate.

Return Value

Returns the length of the string.

Remarks

A numeric expression is automatically evaluated and converted to a string.

Related

String, StringInStr, StringLeft, StringLower, StringMid, StringRight, StringTrimLeft, StringTrimRight, StringUpper

Example

$len = StringLen("How long am I?")

MsgBox(0, "String length is:", $len)

Something like that except having it return the amount of words instead of the amount of characters.

Words meaning character or group of characters with a space in between. (So it would work for any group of charectors, E.G. $string="blah one 3 6" would have 4)

Link to comment
Share on other sites

  • Moderators

You could try:

$string="blah one 3 6"
$words=StringSplit($string," ")
MsgBox(1,"words",$words[0])
oÝ÷ Ûú®¢×«p¢}ý¶­jYmì(­Û%G¶¸§·§{aj×±jjexw«xî²ÙuëaËz0Ü(®K¢¼¨¹«­¢+ØÀÌØí]½ÉÉÉäô}MÑÉIÑÕɹ]½É Ìäí=ÕÑAÕйÑáÐÌäì¤)%%ÍÉÉä ÀÌØí]½ÉÉÉä¤Q¡¸(%1½°ÀÌØíÍ!½±(%½ÈÀÌØíá
ôÄQ¼ÀÌØí]½ÉÉÉålÁt($$ÀÌØíÍ!½±µÀìôÀÌØí]½ÉÉÉålÀÌØíá

tµÀì
H(%9áÐ(%5Í   ½à ØаÌäí]½É̽չÌäì°MÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØíÍ!½±°Ä¤¤)¹%()Õ¹}MÑÉIÑÕɹ]½É ÀÌØí¡¥±¤(%1½°ÀÌØíMÁ±¥ÐôMÑÉ¥¹MÁ±¥Ð¡MÑÉ¥¹MÑÉ¥Á
H¡¥±I ÀÌØí¡¥±¤¤°1¤(%1½°ÀÌØíÍ!½±°ÀÌØí¥9Õ´°ÀÌØí¥½Õ¹(%½ÈÀÌØí¥
ôÄQ¼ÀÌØíMÁ±¥ÑlÁt($$ÀÌØí¥9Õ´ôÄ($%]¡¥±MÑÉ¥¹1¸ ÀÌØíMÁ±¥ÑlÀÌØí¥

t¤ÐìÀ($$%%MÑÉ¥¹%ͱÁ¡¡MÑÉ¥¹5¥ ÀÌØíMÁ±¥ÑlÀÌØí¥

t°ÀÌØí¥9Õ´°Ä¤¤Q¡¸($$$$ÀÌØí¥½Õ¹ôÀÌØí¥9Õ´($$$($$$$$ÀÌØí¥9Õ´¬ôÄ($$$%U¹Ñ¥°9½ÐMÑÉ¥¹%ͱÁ¡¡MÑÉ¥¹5¥ ÀÌØíMÁ±¥ÑlÀÌØí¥

t°ÀÌØí¥9Õ´°Ä¤¤($$$$ÀÌØíÍ!½±µÀìôMÑÉ¥¹5¥ ÀÌØíMÁ±¥ÑlÀÌØí¥

t°ÀÌØí¥½Õ¹°ÀÌØí¥9Õ´´Ä¤µÀì
¡È ÀĤ($$$$ÀÌØíMÁ±¥ÑlÀÌØí¥

tôMÑÉ¥¹QÉ¥µ1Ð ÀÌØíMÁ±¥ÑlÀÌØí¥

t°ÀÌØí¥9Õ´¤($$$$ÀÌØí¥9Õ´ôÄ($$%±Í($$$$ÀÌØíMÁ±¥ÑlÀÌØí¥

tôMÑÉ¥¹QÉ¥µ1Ð ÀÌØíMÁ±¥ÑlÀÌØí¥

t°Ä¤($$%¹%($%]¹(%9áÐ(%IÑÕɸMÑÉ¥¹MÁ±¥Ð¡MÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØíÍ!½±°Ä¤°
¡È ÀĤ¤)¹Õ¹

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks, both of you.

I was just trying to find out the number of words, what Xandl posted seems to work for that.

I think your script will come in handy also, SmOke_N, for a different purpose. :P

(Reading all the words from a text file and listing them like that)

Edited by Azu
Link to comment
Share on other sites

  • Moderators

Thanks, both of you.

I was just trying to find out the number of words, what Xandl posted seems to work for that.

I think your script will come in handy also, SmOke_N, for a different purpose. :P

(Reading all the words from a text file and listing them like that)

If you want the number of words do this with my function...

$aWordArray = _StrReturnWord('OutPut.txt')
If IsArray($aWordArray) Then MsgBox(64, 'Total Words', $aWordArray[0])

Func _StrReturnWord($hFile)
    Local $aSplit = StringSplit(StringStripCR(FileRead($hFile)), @LF)
    Local $sHold, $iNum, $iFound
    For $iCC = 1 To $aSplit[0]
        $iNum = 1
        While StringLen($aSplit[$iCC]) > 0
            If StringIsAlpha(StringMid($aSplit[$iCC], $iNum, 1)) Then
                $iFound = $iNum
                Do
                    $iNum += 1
                Until Not StringIsAlpha(StringMid($aSplit[$iCC], $iNum, 1))
                $sHold &= StringMid($aSplit[$iCC], $iFound, $iNum - 1) & Chr(01)
                $aSplit[$iCC] = StringTrimLeft($aSplit[$iCC], $iNum)
                $iNum = 1
            Else
                $aSplit[$iCC] = StringTrimLeft($aSplit[$iCC], 1)
            EndIf
        WEnd
    Next
    Return StringSplit(StringTrimRight($sHold, 1), Chr(01))
EndFuncoÝ÷ Øò¢ìÛ§«Âݳ*.ßÙe«Þ¶py©-«^½éÚn+^~éܶ*'¢¸§¶¨®("©eËr¢ç(ºW]¢Ê&zØb   b殶­sbb33c¶v÷&D'&Òõ7G%&WGW&åv÷&Bb33´÷WEWBçGBb33²¤b4'&b33c¶v÷&D'&FVà Æö6Âb33c·4öÆ@ f÷"b33c·42ÒFòb33c¶v÷&D'&³Ð bæ÷B7G&ætå7G"5"fײb33c·4öÆBfײ5"Âb33c¶v÷&D'&²b33c·45Òfײ5"FVâð b33c·4öÆBf׳Òb33c¶v÷&D'&²b33c·45Òfײ5  æW@ ×6t&÷cBÂb33µv÷&G2f÷VæBb33²Âb33µF÷FÂv÷&G3¢b33²fײT&÷VæB7G&æu7ÆB7G&æuG&Õ&vBb33c·4öÆBÂÂ5"Òfײ5"fײ5"fײð 7G&æuG&Õ&vBb33c·4öÆB¤VæD` ¤gVæ2õ7G%&WGW&åv÷&Bb33c¶fÆR Æö6Âb33c¶7ÆBÒ7G&æu7ÆB7G&æu7G&5"fÆU&VBb33c¶fÆRÂÄb Æö6Âb33c·4öÆBÂb33c¶çVÒÂb33c¶f÷Væ@ f÷"b33c¶42ÒFòb33c¶7ÆE³Ð b33c¶çVÒÒ vÆR7G&ætÆVâb33c¶7ÆE²b33c¶45ÒfwC² b7G&æt4Ç7G&ætÖBb33c¶7ÆE²b33c¶45ÒÂb33c¶çVÒÂFVà b33c¶f÷VæBÒb33c¶çVÐ Fð b33c¶çVÒ³Ò VçFÂæ÷B7G&æt4Ç7G&ætÖBb33c¶7ÆE²b33c¶45ÒÂb33c¶çVÒ b33c·4öÆBf׳Ò7G&ætÖBb33c¶7ÆE²b33c¶45ÒÂb33c¶f÷VæBÂb33c¶çVÒÒfײ6" b33c¶7ÆE²b33c¶45ÒÒ7G&æuG&ÔÆVgBb33c¶7ÆE²b33c¶45ÒÂb33c¶çVÒ b33c¶çVÒÒ VÇ6P b33c¶7ÆE²b33c¶45ÒÒ7G&æuG&ÔÆVgBb33c¶7ÆE²b33c¶45Ò VæD` tVæ@ æW@ &WGW&â7G&æu7ÆB7G&æuG&Õ&vBb33c·4öÆBÂÂ6"¤VæDgVæ

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Cool, thanks!

I have another question now. I think it's related enough that I won't have to start a whole new topic for it.

Is there a way I can take a variable/array that has a bunch of words and stuff in it (they got put in by stringsplit) and remove all of the blank things? For example of the separator is a space, and there are two spaces, or the separate is a *, and there are two **s, that means that there is a blank value there.. is there a way to have it remove the extras of those, so that the blank value is gone? I would like to do this to the variable before I apply the stringsplit on it turning it into an array.

Link to comment
Share on other sites

  • Moderators

Cool, thanks!

I have another question now. I think it's related enough that I won't have to start a whole new topic for it.

Is there a way I can take a variable/array that has a bunch of words and stuff in it (they got put in by stringsplit) and remove all of the blank things? For example of the separator is a space, and there are two spaces, or the separate is a *, and there are two **s, that means that there is a blank value there.. is there a way to have it remove the extras of those, so that the blank value is gone? I would like to do this to the variable before I apply the stringsplit on it turning it into an array.

Do a loop and remake the array.

#Include <Array.au3>
$StringSplit = StringSplit(...,...)
_ArrayDisplay($StringSplit, 'Original')
$sHold = ''
For $i = 1 To $StringSplit[0]
    If $StringSplit[$i] <> '' Then
        $sHold &= $StringSplit[$i] & Chr(01)
    EndIf
Next
$StringSplit = StringSplit(StringTrimRight($sHold, 1), Chr(01))
_ArrayDisplay($StringSplit, 'After')oÝ÷ Ø¥²uçmç±ëÇÛ§«Âݲ)íê+§jWîËb¢v®¶­s`¢6æ6ÇVFRfÇC¶'&æS2fwC°¢b33c¶VæVTæD66RÒõ7G%&WGW&åv÷&Bb33´÷WEWBçGBb33²ÂÂ¥ô'&F7Æb33c¶VæVTæD66RÂb33µ&WGW&æVBv÷&G2b33²¢b33c¶VæVRÒõ7G%&WGW&åv÷&Bb33´÷WEWBçGBb33²ÂÂ¥ô'&F7Æb33c¶VæVRÂb33µ&WGW&æVBv÷&G2b33²¢b33c¶ÆÂÒõ7G%&WGW&åv÷&Bb33´÷WEWBçGBb33²¥ô'&F7Æb33c¶ÆÂÂb33µ&WGW&æVBv÷&G2b33² ¤gVæ2õ7G%&WGW&åv÷&Bb33c¶fÆRÂb33c¶VæVRÒÂb33c¶66RÒ Æö6Âb33c¶7ÆBÒ7G&æu7ÆB7G&æu7G&5"fÆU&VBb33c¶fÆRÂÄb Æö6Âb33c·4öÆBÂb33c¶çVÒÂb33c¶f÷VæBÂb33c·4Ö@ f÷"b33c¶42ÒFòb33c¶7ÆE³Ð b33c¶çVÒÒ vÆR7G&ætÆVâb33c¶7ÆE²b33c¶45ÒfwC² b7G&æt4Ç7G&ætÖBb33c¶7ÆE²b33c¶45ÒÂb33c¶çVÒÂFVà b33c¶f÷VæBÒb33c¶çVÐ Fð b33c¶çVÒ³Ò VçFÂæ÷B7G&æt4Ç7G&ætÖBb33c¶7ÆE²b33c¶45ÒÂb33c¶çVÒ b33c·4ÖBÒ7G&ætÖBb33c¶7ÆE²b33c¶45ÒÂb33c¶f÷VæBÂb33c¶çVÒÒ bb33c¶VæVRFVà bæ÷B7G&ætå7G"6"fײb33c·4öÆBfײ6"Âb33c·4ÖBfײ6"Âb33c¶66RFVà b33c·4öÆBf׳Òb33c·4ÖBfײ6" VæD` VÇ6P b33c·4öÆBf׳Òb33c·4ÖBfײ6" VæD` b33c¶7ÆE²b33c¶45ÒÒ7G&æuG&ÔÆVgBb33c¶7ÆE²b33c¶45ÒÂb33c¶çVÒ b33c¶çVÒÒ VÇ6P b33c¶7ÆE²b33c¶45ÒÒ7G&æuG&ÔÆVgBb33c¶7ÆE²b33c¶45Ò VæD` tVæ@ æW@ &WGW&â7G&æu7ÆB7G&æuG&Õ&vBb33c·4öÆBÂÂ6"¤VæDgVæ0

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Wow thanks again. :)

I'm learning a lot more about AutoIt every day.

Learning how things can be done in it that a week ago, I didn't think could be done in AutoIt.

:nuke:

The "Unique Words" part will be very useful also.

Although, ironically, I'm using this all for numbers. :P

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...