Jump to content

Count in a line shows more characters than available


Recommended Posts

Hi

I am trying to read a line from a file. Post read i am counting the number of characters in the line by using StringLen.

The line is sc marks:1
Which is 10 letters but the string length is returning length as 14.
Can i know the reason behind it??

I wanted to pick the last number in the line.
Can i get any solutions to the problem i am facing???
                  

Link to comment
Share on other sites

Can I suggest you write a short sample code, illustrating this. I suspect that in the process of doing that you will find your problem:

Step one: set a $string = " sc marks:1", StringLen and msgbox the result. Then cut and paste the same string into a file and repeat.

Perhaps you have a special character or text encoding in your file? Even if you don't find your problem it makes it quick for us to see exactly what you have tried and its output.

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

1 hour ago, SlackerAl said:

Can I suggest you write a short sample code, illustrating this. I suspect that in the process of doing that you will find your problem:

Step one: set a $string = " sc marks:1", StringLen and msgbox the result. Then cut and paste the same string into a file and repeat.

Perhaps you have a special character or text encoding in your file? Even if you don't find your problem it makes it quick for us to see exactly what you have tried and its output.

Hi

i have tried this code
#include <MsgBoxConstants.au3>
#include <File.au3>
$File = @Dir \Text.txt
$Open = FileOpen($File, 0)
$Read = FileRead($Open)
MsgBox ($MB_SYSTEMMODAL, "read:", $Read )
$len = StringLen($Read)
MsgBox ($MB_SYSTEMMODAL, "Length:", $len )

i have copied text to source file and then closed it by saving it.

 

Text file:

1 makers:1

Value returned is 14
total number of characters present are 10

Link to comment
Share on other sites

  • Moderators

sree161,

Please post a copy of the file itself - my guess is that there are some additional EOLs within it.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi.

$File = @Dir \Text.txt

couldn't be correct. What exactly is the path to the file?

Do you mean:

$File = @ScriptDir & "\Text.txt"

Conrad

Edited by Simpel
code in tags
SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

No problems on my system.
Suggestion to run below to see AutoIt works fine (be aware it creates  test.txt automatically overwriting any existing file)

#include <MsgBoxConstants.au3>
#include <File.au3>
#include <String.au3>

$File = @ScriptDir & "\Test.txt"

; Open the file for writing (append to the end of a file) and store the handle to a variable.
Local $hFileOpen = FileOpen($File,$FO_OVERWRITE + $FO_UTF8)
If $hFileOpen = -1 Then
   MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
   Return False
EndIf

filewrite($hFileOpen,"sc marks:1" )
fileclose($hFileOpen)

$Open = FileOpen($File, 0)
$Read = FileRead($Open)
consolewrite("read:" & $Read & @CRLF)
$len = StringLen($Read)
consolewrite("Length:" & $len & @CRLF )
$blen = binaryLen($Read)
consolewrite("Binary length:" & $blen & @CRLF )
$hexString=_stringtohex($read)
consolewrite("hex:" & $hexString & @CRLF )

 

Link to comment
Share on other sites

4 hours ago, sree161 said:

Hi all,
I used a hotkey to paste data to my notepad due to which the pointer goes to next line after pasting.
Will this be the reason for the problem i am facing???

please try what i suggested in post #8.

Show your code for the hotkey (i assume for the moment its just ctrl+v)

Will this be the reason for the problem i am facing???

Most likely you indeed have special characters in your string like a Start of file (BOM),  Some messing up with unicode/ascii/.... characterset. But from what you describe its impossible to reveal your problem (you have to attach the file you read or test post#8). Each line can have a CRLF CRLF which is then 4 characters invisible to enduser.

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