Search code examples
kdbq-lang

Reduce multiple whitespaces to a single space in KDB+/Q


To get from "a b" to "a b"

ssr["a         b";"[ ]+";" "]

doesn't seem to work. Thanks!


Solution

  • You can use the following which treats each repeating space as a pair, then using over, 'replaces' these with a single space.

    q)x:"This         is    a    test"
    
    q)(" "sv"  "vs)/[x]
    
    "This is a test"