
-----------------------------------
Jas
Wed May 18, 2005 9:11 pm

skipping white spaces help
-----------------------------------
what if  an array record had a value with white spaces at the end, and u wanted to save that value, into a different variable, but without the white spaces, how would u do that. This is an example of what i mean





% WithWhiteSpace(1).name can have value of "Bob          "

for i : 1..count
WithoutWhiteSpace(i).name := WithWhiteSpace(i).name, skip
end for



when i use the ", skip" i get the error "Syntax error at ','  "

-----------------------------------
Delos
Wed May 18, 2005 9:31 pm


-----------------------------------
Well, if you can assume that the *only* white space that exists is at the end of the string, the index() the position of the first space, and extract the required string.
If you have more white space, some nifty index()ing will solve things for you.

If you don't know any of this, look up String Manipulation in the Tutorials.  Or check out Cervantes list of Tutorials...it will help a lot!

-----------------------------------
Jas
Wed May 18, 2005 9:55 pm


-----------------------------------
acutally, the variable could have a first and last name. but the variable for sure has spaces at the end. for example: 



%WithWhiteSpace(1).name can have value of "Bob Grey Smith          "





How would you ignore the spaces in between, but "delete" the spaces at the end?

-----------------------------------
Jas
Thu May 19, 2005 12:28 am


-----------------------------------
ok took me quite a while to figure out, but i ended up with this:


var word1 : string
var word : string
put "Enter full name (with spaces at the end): " % eg: "Bob Grey      "
get word : * % max 3 words

if index (word, " ") not= 0 then
    var place : int
    place := index (word, " ")
    if index (word (place .. place + 1), " ") not= 0 and index (word (place + 1 .. place + 2), " ") not= 0 then
        word1 := word (1 .. place - 1)
    elsif index (word (place + 1 .. *), " ") not= 0 then
        place := index (word (place + 1 .. *), " ") + place
        if index (word (place + 1 .. *), " ") not= 0 and index (word (place + 1 .. place + 2), " ") not= 0 then
            word1 := word (1 .. place - 1)
        elsif index (word (place + 1 .. *), " ") not= 0 then
            place := index (word (place + 1 .. *), " ") + place
            if index (word (place + 1 .. *), " ") not= 0 and index (word (place + 1 .. place + 2), " ") not= 0 then
                word1 := word (1 .. place - 1)
            end if
        end if
    end if
end if

put word1, "abc" % no spaces at end of word!!! :)


-----------------------------------
Bacchus
Thu May 19, 2005 6:06 am


-----------------------------------
couldnt you just do:
var word:string
get word:*
word:=word(1..index(word,"  ")-1)
put word

-----------------------------------
MysticVegeta
Thu May 19, 2005 6:23 am


-----------------------------------
Yes but what if the spaces are : "Bob           is   bad   "
None of them works for that so here is my code:
var a : string
get a : *
var count : int
loop
    for s : 1 .. length (a)
        if a (s) = " " then
            count := s
            exit
        end if
    end for
    if ((count + 1) > length (a)) or (count = length (a)) then
        a := a (1 .. count - 1)
    else
        a := a (1 .. count - 1) + a (count + 1 .. *)
    end if
    if index (a, " ") = 0 then
        put a
        exit
    end if
end loop


-----------------------------------
Cervantes
Thu May 19, 2005 7:06 am


-----------------------------------
I'm pretty sure he doesn't want all the spaces deleted, only the ones at the end:

var name : string
get name : *
for decreasing i : length (name) .. 1
    if name (i) ~= " " then
        name := name (1 .. i)
        exit
    end if
end for
put name ..
put "."

The put "." is simply to show where the name string ends.

-----------------------------------
Jas
Thu May 19, 2005 4:18 pm


-----------------------------------
wow, u really shortened it up, im impressed Cervantes!!
