Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » ocl contains operations over strings
ocl contains operations over strings [message #25556] Tue, 29 May 2007 11:12 Go to next message
Eclipse User
Originally posted by: angel.calvo.centic.es

Hello!
Is there any operation in OCL which returns if a string contains spaces?

Thanks.
Re: ocl contains operations over strings [message #25596 is a reply to message #25556] Tue, 29 May 2007 11:32 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Angel,

Nope. But, you can do this:

Sequence{1..s.size()}->exists(i | s.substring(i, i) = ' ')

to determine whether a string s contains spaces.

You can even use OCL to define this as an additional operation in your
environment:

context String
def: hasSpace : boolean =
Sequence{1..self.size()}->exists(i | self.substring(i, i) = ' ')

HTH,

Christian


Angel Luis Calvo Ortega wrote:

> Hello!
> Is there any operation in OCL which returns if a string contains spaces?
>
> Thanks.
Re: ocl contains operations over strings [message #25801 is a reply to message #25596] Tue, 29 May 2007 13:16 Go to previous messageGo to next message
Eclipse User
Originally posted by: angel.calvo.centic.es

Thanks a lot Christian!
It's worked perferctly.


Christian W. Damus escribió:
> Hi, Angel,
>
> Nope. But, you can do this:
>
> Sequence{1..s.size()}->exists(i | s.substring(i, i) = ' ')
>
> to determine whether a string s contains spaces.
>
> You can even use OCL to define this as an additional operation in your
> environment:
>
> context String
> def: hasSpace : boolean =
> Sequence{1..self.size()}->exists(i | self.substring(i, i) = ' ')
>
> HTH,
>
> Christian
>
>
> Angel Luis Calvo Ortega wrote:
>
>> Hello!
>> Is there any operation in OCL which returns if a string contains spaces?
>>
>> Thanks.
>
Re: ocl contains operations over strings [message #923023 is a reply to message #25556] Tue, 25 September 2012 10:44 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Hi friends,

leveraging the post I would like to know if have way to know if a string has a substring.

For example to know if string: 'return 123+996*oldVar' has substring 'return'

If you can help me, I thank you.
I already tried formulate the expression but I had no success.

Thank you for the help and I'm sorry about the english.

Pablo.
Re: ocl contains operations over strings [message #923093 is a reply to message #923023] Tue, 25 September 2012 11:39 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4025
Registered: July 2009
Senior Member
Hi

The OCL string library has been gradually improving.

The Juno release of Eclipse OCL has further String functions such as
regex. See the Help documentation.

Regards

Ed Willink

On 25/09/2012 15:44, Pablo Silva wrote:
> Hi friends,
>
> leveraging the post I would like to know if have way to know if a
> string has a substring.
>
> For example to know if string: 'return 123+996*oldVar' has substring
> 'return'
>
> If you can help me, I thank you.
> I already tried formulate the expression but I had no success.
>
> Thank you for the help and I'm sorry about the english.
>
> Pablo.
Previous Topic:Simplify OCL query
Next Topic:OCl variable of type EEList
Goto Forum:
  


Current Time: Wed Aug 20 10:53:57 EDT 2014

Powered by FUDForum. Page generated in 0.01871 seconds