Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: awk challenge
Improved version. (Remove @ at beginning of lines.)

@# Like split(), but returns array of the matching portions
@# instead of the non-matching ones.
@# Only works if string doesn't contain ASCII 1.
@function splitp(s,A,re,        mark,_mark )
@{ delete A
@  mark = sprintf( "%c", 1 )
@  _mark = "[^" mark "]*"
@  if ( gsub( re, mark "&" mark, s  ) )
@    gsub( "^" _mark mark "|" mark _mark "$", "", s )
@  else
@    s = ""
@  return split( s, A, mark _mark mark )
@}
@
@BEGIN{
@  test( "foobar", "x" )
@  test( "foobar", "b" )
@  test( "foobar", "^.|.$" )
@  test( "  ", " +" )
@  test( "  The quick red fox.  ", " +" )
@}
@
@function test( s,re   ,wheat,chaff )
@{
@  print s "<  (Regexp.: " re ")"
@  split(  s, wheat, re )
@  splitp( s, chaff, re )
@
@  for (i=1; i in wheat; i++)
@    printf "%s|", wheat[i]
@  print "(wheat)"
@  for (i=1; i in chaff; i++)
@    printf "%s|", chaff[i]
@  print "(chaff)"
@
@  for (i=1; i in wheat; i++)
@  { printf "%s", wheat[i]
@    if (i in chaff)
@      printf "%s", chaff[i]
@  }
@  print "<"
@  print "----------------------------"
@}


Report this thread to moderator Post Follow-up to this message
Old Post
William James
12-27-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:24 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.