number of characters in a string

M

machoq

I have reading a line from a text file
the line is like

abc\"123
I need to find the number of characters in this string... (which
should be 8, however if i do a

$var = $line;
print length($var); i get 7

How do i workaround it ?
regards
-Machoq !
 
X

Xevo

I have reading a line from a text file
the line is like

abc\"123
I need to find the number of characters in this string... (which
should be 8, however if i do a

$var = $line;
print length($var); i get 7

How do i workaround it ?
regards
-Machoq !

Well if the line is "abc\"123", then the \ would be counted as a
backreference for the " character. Therefore, \" is only counted as
one character. This is only a guess though since you didn't post the
exact code.
 
P

Paul Lalli

Xevo said:
(e-mail address removed) (machoq) wrote in message

Well if the line is "abc\"123", then the \ would be counted as a
backreference for the " character. Therefore, \" is only counted as
one character. This is only a guess though since you didn't post the
exact code.

If the line is being read from a text file, as the OP claimed, than this
is not true. The \ will be a literal \. \ is only treated 'special'
within literal code, not within data.

Paul Lalli
 
A

Anno Siegel

Xevo said:
(e-mail address removed) (machoq) wrote in message


Well if the line is "abc\"123", then the \ would be counted as a
backreference for the " character. Therefore, \" is only counted as
^^^^^^^^^^^^^

Backreferences are a different case of "\". You mean "quote" or "escape"
(sometimes called "backwhack").

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,269
Messages
2,571,100
Members
48,773
Latest member
Kaybee

Latest Threads

Top