One question about text. [SOLVED]

For questions about using Classic.

Post » Sun Mar 20, 2011 11:23 am

Is there a way to recognize only a part of a word and change the text?
Example: I want to add the plural of Fairy. Can i make something like: If "y" is at the end of the word, delete it and add ies?
Thanks for the help.
B
1
G
1
Posts: 5
Reputation: 435

Post » Sun Mar 20, 2011 11:27 am

I'm not sure if I can help with reference to Constuct, but in my general experience with programming, you can normally do that with variables and arrays if i'm not mistaken.
B
2
G
1
Posts: 10
Reputation: 470

Post » Sun Mar 20, 2011 6:29 pm

I haven't used text too extensively, but it sounds like you might need an array for that. Store each letter separately and then check the last position for a y, that shouldn't be too difficult. But then again, I haven't used arrays either. :P
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Sun Mar 20, 2011 6:53 pm

Maybe this would help? just press the plural button to change the text.
[url:zewcjvk5]http://dl.dropbox.com/u/7658043/plural.cap[/url:zewcjvk5]
B
22
S
3
G
6
Posts: 1,356
Reputation: 7,141

Post » Sun Mar 20, 2011 7:29 pm

[quote="DravenX":3l88zhgr]Maybe this would help? just press the plural button to change the text.
[url:3l88zhgr]http://dl.dropbox.com/u/7658043/plural.cap[/url:3l88zhgr][/quote:3l88zhgr]
I need to change all the words ending with y to plural.


[quote="SullyTheStrange":3l88zhgr]I haven't used text too extensively, but it sounds like you might need an array for that. Store each letter separately and then check the last position for a y, that shouldn't be too difficult. But then again, I haven't used arrays either. :P[/quote:3l88zhgr]
I don't know how to use array, someone can help me?
B
1
G
1
Posts: 5
Reputation: 435

Post » Sun Mar 20, 2011 8:57 pm

Replacing isn't that difficult. The system expressions "Get right substring", "Get left substring" and "Get string length" will help you with it.

As a first exercise do this: Create a text box and create a private variable with the name word, the type text and the initial value fairy.
In the event sheet insert a "start of layout"-event. Create a sub-event using System - Compare.
In the first field enter right(Text.Value('word'), 1), comparison equal to, the second field should be "y".
Now create an action to this condition. Set the text of the text box to left(Text.Value('word'), len(Text.Value('word')) - 1) & "ies"

[code:uzzt57u4]+ System: right(Text.Value('word'), 1) Equal to "y"
-> Text: Set text to left(Text.Value('word'), len(Text.Value('word')) - 1) & "ies"
[/code:uzzt57u4]

What is going on here is that you check if the last letter of the variable word equals "y". right(text, count) returns the rightmost count letters of word. right("fairy", 1) returns "y", right("fairy", 2) would return "ry", etc.
In our case the condition becomes true and the action is performed. Here we retrieve the leftmost letters of word. left("fairy", 1) would return "f", left("fairy", 2) returns "fa", etc. We just need to know the length of the word to get rid of the "y". len(Text.Value('word')) returns the number of letters in word. We just need to substract 1 from the length ("y" is just one letter). Now left(Text.Value('word'), len(Text.Value('word')) - 1) returns "fair" and we just need to add our new ending. "fair" & "ies" concatenates to "fairies".
Success! :mrgreen:

You will most likely work with text, not just words. So you need to find a way to seperate the words of the text first and then use the above method. You will see that GetToken(String, Index, Separator) is very helpful for that. For example, GetToken("I see fairy", 3, " ") will return "fairy", which you then could correct to "fairies", while rebuilding the text in a new variable or text box or whatever suits your needs.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Mar 21, 2011 2:20 pm

Thank you very much!
B
1
G
1
Posts: 5
Reputation: 435


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests