Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get a "\n" from a string?

Status
Not open for further replies.

firelex

Programmer
Jan 10, 2002
118
DE
Hello, all!
My problem is:

I have a proc that parses strings with [tt]regexp[/tt] for "bad" characters(e.g. {\{\}\=\-\,\.} ). If found -> [tt]return 0[/tt], [tt]1[/tt] otherwise.
The question is: how can I get out if the string contains a [tt]"\n"[/tt] character?

I know - it is possible with [tt]scan[/tt], but the easier way for me were something, that could be added to a [tt]regexp[/tt] check.

Any ideas?
 
Are you having trouble representing a newline char in your
regexp?
Try \\n
 
That's right. I cannot find a symbol for the newline for my regexp.
[tt]\\n[/tt] doesn't work also. I've tried it already.

Look, this is my [tt]regexp[/tt] :
[tt]{[^\{\}\!\\n]*$}[/tt]
If a char isn't in the range -> the char is OK. The problem is : it doesn't see the newline as [tt]\\n[/tt].
 
It works both ways here.
Code:
(mars) set nl [format %c 0x0A]


(mars) 55 % set boo "this is a test\n of the emergency\n broadcast system"
this is a test
 of the emergency
  broadcast system
(mars) 56 % regexp "$nl" $boo all
1
(mars) 57 % puts $all


(mars) 58 % puts "\\n"
\n
(mars) 59 % set nll "\\n"
\n
(mars) 60 % regexp "$nll" $boo all
1
(mars) 61 % puts $all


(mars)
[\code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top