How to split a string at a particular character in Rebol -


i haven't figure out how split string in cleaner way.

 ref: copy/part (find line "#") -15  rest2: copy/part (skip (find line "#") 1) 450 

-15 going beginning , 450 go end.

it not nice because put value.

what proper solution ?

a warning front: there many different ways achieve in rebol. you'll quite few different suggestions.

for start, let's stick original approach of using find.

when use find series, new view onto underlying series data, positioned @ different offset start of series data.

let's start example data:

>> line: copy "this foo#and here comes long bar" == "this foo#and here comes long bar" 

let's find # character within line, , refer result pos:

>> pos: find line "#" == "#and here comes long bar" 

as can see, gives second part (what called rest2) of split. you'll have skip past delimiter (and copy resulting string, make independent original line string):

>> rest: copy next pos == "and here comes long bar" 

for extracting initial part, can use nice feature of copy/part. documentation of "/part" refinement (try help copy) says: "limits given length or position" (emphasis mine). have position handy pos. so:

>> ref: copy/part line pos == "this foo" 

and there go! complete code:

pos: find line "#" ref: copy/part line pos rest: copy next pos 

for reference, here's parse-based approach:

parse line [copy ref "#" skip copy rest end] 

i'll let stand without further explanation. if want know more parse, place start venerable "parsing" chapter in rebol/core users guide (originally written rebol 2.3, basics still same in current rebol 2 , 3 versions).

one ancillary note @ end: instead of single-item string "#" use character written #"#" in rebol.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -