comparison src/ut/lu/lu.go @ 21:4232b4cbeeb5

ul: add replace.
author pyon@macmini
date Sun, 24 Jun 2018 06:32:13 +0900
parents 8008046c8d76
children
comparison
equal deleted inserted replaced
20:0a6541999b53 21:4232b4cbeeb5
355 355
356 } 356 }
357 } 357 }
358 } 358 }
359 359
360 /* replace: */ 360 /* replace: done. */
361 func Replace( s, t string, files []string ) { 361 func Replace( s, t string, files []string ) {
362 if len( files ) == 0 { 362 if len( files ) == 0 {
363 input := bufio.NewScanner( os.Stdin ) 363 input := bufio.NewScanner( os.Stdin )
364 for input.Scan() { 364 for input.Scan() {
365 str := strings.Replace( input.Text(), s, t, -1 )
366 fmt.Println( str )
365 } 367 }
366 } else { 368 } else {
367 for _, file := range files { 369 for _, file := range files {
368 f, _ := os.Open( file ) 370 f, _ := os.Open( file )
369 input := bufio.NewScanner( f ) 371 input := bufio.NewScanner( f )
370 for input.Scan() { 372 for input.Scan() {
373 str := strings.Replace( input.Text(), s, t, -1 )
374 fmt.Println( str )
371 } 375 }
372 f.Close() 376 f.Close()
373 } 377 }
374 } 378 }
375 } 379 }