Yep, that is real old fashioned coding. But what if there are three contiguous spaces?

Craig
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Just another loop ;-)dunbarx wrote:But what if there are three contiguous spaces?
Code: Select all
repeat until offset(" ", MyStr) = 0
Well: I'd be inclined to run through the text and replace all the quotes with some other symbol that isn't used anywhereas I understand, the OP wants after the partitioning into words the quotes back to where they were before, for example
"Here I am" should translate to the three 'parts': <"here> and <I> and <am!">.
This is hardcore code. It runs until there are no more consecutive spaces, or until all CPUs go up in flames. Whatever comes first!dunbarx wrote:But what if there are four spaces?
From the demo stack above:richmond62 wrote:I'd be inclined to run through the text and replace all the quotes with some other symbol that isn't used anywhere [...]
Code: Select all
put ",.;:-?*1234567890" & quote into KillIt -- this is not wanted.
repeat for each char TheChar in MyStr
if theChar is not in KillIt then put theChar after MyVar
if theChar is quote then put "-" after MyVar
end repeat
richmond62 wrote:And then replace the other symbols with quotes again.
Code: Select all
replace "-" with quote in MyList
dunbarx wrote:It is ASCII 202, not space.
Code: Select all
repeat until offset(" ", MyStr) = 0
Code: Select all
unction killSpaces MyStr
return charToNum(" ")
end killSpaces
Following your request,tonymac wrote: (HERE IS SOME TEXT. IT'S EXACTLY 100 WORDS LONG. COPY/PASTE IT INTO A TEXT EDITOR AND VERIFY THE WORD COUNT)
Thanks for any input.
Code: Select all
on mouseUp
put fld 1 into s
put 0 into i
repeat for each trueWord w in s
add 1 to i
put i && w &cr after t
end repeat
put t into fld 2
end mouseUp
Code: Select all
1 Once
2 upon
3 a
4 time
5 there
6 were
7 four
8 little
9 Rabbits
10 and
11 their
12 names
13 were
14 Flopsy
15 Mopsy
16 Cotton
17 tail
18 and
19 Peter
20 They
21 lived
22 with
23 their
24 Mother
25 in
26 a
27 sand
28 bank
29 underneath
30 the
31 root
32 of
33 a
34 very
35 big
36 fir
37 tree
38 Now
39 my
40 dears
41 said
42 old
43 Mrs
44 Rabbit
45 one
46 morning
47 you
48 may
49 go
50 into
51 the
52 fields
53 or
54 down
55 the
56 lane
57 but
58 don't
59 go
60 into
61 Mr
62 McGregor's
63 garden
64 your
65 Father
66 had
67 an
68 accident
69 there
70 he
71 was
72 put
73 in
74 a
75 pie
76 by
77 Mrs
78 McGregor
79 Now
80 run
81 along
82 and
83 don't
84 get
85 into
86 mischief
87 Then
88 Mrs
89 Rabbit
90 took
91 a
92 basket
93 and
94 her
95 umbrella
96 and
97 went
98 through
99 the
100 woods
101 to
102 the
103 baker's
Code: Select all
on mouseUp
local output
repeat with i = 1 to the number of words in the text of field "log"
if (char 1 of word i of the text of field "log" = QUOTE) then
local tempWord
put word i of the text of field "log" into tempWord
delete char 1 of tempWord
delete char -1 of tempWord
repeat with j = 1 to the number of words in tempWord
put word j of tempWord & LF after output
end repeat
else
put word i of the text of field "log" & LF after output
end if
end repeat
put the number of words of output
end mouseUp
Code: Select all
on mouseUp
put fld "log" into s
put TrueWordList(s) into fld "out1"
put ShaoSeanList(s) into fld "out2"
end mouseUp
function TrueWordList s
put 0 into i
repeat for each trueWord w in s
add 1 to i
put i && w &cr after t
end repeat
return t
end TrueWordList
function ShaoSeanList s
repeat with i = 1 to the number of words in s
if (char 1 of word i of s = QUOTE) then
local tempWord
put word i of s into tempWord
delete char 1 of tempWord
delete char -1 of tempWord
repeat with j = 1 to the number of words in tempWord
put word j of tempWord & LF after output
end repeat
else
put word i of s & LF after output
end if
end repeat
--
put 0 into i
repeat for each word w in output
add 1 to i
put i && w &cr after tOutList
end repeat
return tOutList
end ShaoSeanList
Code: Select all
1 Once
2 upon
3 a
4 time
5 there
6 were
7 four
8 little
9 Rabbits
10 and
11 their
12 names
13 were
14 Flopsy
15 Mopsy
16 Cotton
17 tail
18 and
19 Peter
20 They
21 lived
22 with
23 their
24 Mother
25 in
26 a
27 sand
28 bank
29 underneath
30 the
31 root
32 of
33 a
34 very
35 big
36 fir
37 tree
38 Now
39 my
40 dears
41 said
42 old
43 Mrs
44 Rabbit
45 one
46 morning
47 you
48 may
49 go
50 into
51 the
52 fields
53 or
54 down
55 the
56 lane
57 but
58 don't
59 go
60 into
61 Mr
62 McGregor's
63 garden
64 your
65 Father
66 had
67 an
68 accident
69 there
70 he
71 was
72 put
73 in
74 a
75 pie
76 by
77 Mrs
78 McGregor
79 Now
80 run
81 along
82 and
83 don't
84 get
85 into
86 mischief
87 Then
88 Mrs
89 Rabbit
90 took
91 a
92 basket
93 and
94 her
95 umbrella
96 and
97 went
98 through
99 the
100 woods
101 to
102 the
103 baker's
Code: Select all
1 Once
2 upon
3 a
4 time
5 there
6 were
7 four
8 little
9 Rabbits,
10 and
11 their
12 names
13 were--
14 Flopsy,
15 Mopsy,
16 Cotton-tail,
17 and
18 Peter.
19 They
20 lived
21 with
22 their
23 Mother
24 in
25 a
26 sand-bank,
27 underneath
28 the
29 root
30 of
31 a
32 very
33 big
34 fir-tree.
35 Now,
36 my
37 dears,
38 said
39 old
40 Mrs.
41 Rabbit
42 one
43 morning,
44 you
45 may
46 go
47 into
48 the
49 fields
50 or
51 down
52 the
53 lane,
54 but
55 don't
56 go
57 into
58 Mr.
59 McGregor's
60 garden:
61 your
62 Father
63 had
64 an
65 accident
66 there;
67 he
68 was
69 put
70 in
71 a
72 pie
73 by
74 Mrs.
75 McGregor.
76 Now
77 run
78 along,
79 and
80 don't
81 get
82 into
83 mischief.
84 Then
85 Mrs.
86 Rabbit
87 took
88 a
89 basket
90 and
91 her
92 umbrella,
93 and
94 went
95 through
96 the
97 woods
98 to
99 the
100 baker's.