checking a special character in a single string [message #93166] |
Thu, 05 May 2016 07:28  |
Sapna Mishra
Messages: 66 Registered: December 2015
|
Member |
|
|
Hello all,
I have a string say:
obj='J165248.4+363212.5'
I want to know the place where my this + sign has come say here at 10th place .
I did:
n=where(strmatch(obj,'+*',/FOLD_CASE) EQ 1)
but it is simply giving me n=1.
can any one tell how to proceed ?
Also if i want to remove all the numbers after '.' (decimal) how to do?
with strjoin+strsplit it is simply removing decimal sign and clubbing all numbers together. I don't want numbers after decimal how to do???
|
|
|
Re: checking a special character in a single string [message #93169 is a reply to message #93166] |
Thu, 05 May 2016 09:08   |
Burch
Messages: 28 Registered: December 2013
|
Junior Member |
|
|
On Thursday, May 5, 2016 at 9:28:57 AM UTC-5, Sapna Mishra wrote:
> Hello all,
>
> I have a string say:
> obj='J165248.4+363212.5'
>
> I want to know the place where my this + sign has come say here at 10th place .
>
> I did:
> n=where(strmatch(obj,'+*',/FOLD_CASE) EQ 1)
>
> but it is simply giving me n=1.
>
> can any one tell how to proceed ?
>
> Also if i want to remove all the numbers after '.' (decimal) how to do?
> with strjoin+strsplit it is simply removing decimal sign and clubbing all numbers together. I don't want numbers after decimal how to do???
STRMATCH() doesn't give the location of the search string within the input. It simply returns 1 or 0 based upon whether or not the search string is in the input. Also, when I run your code I get n = -1. To get n=1 the search string for STRMATCH() needs to be '*+*'.
Regardless, if you're looking for the location within the input, then the function you want is STREGEX().
IDL> obj='J165248.4+363212.5'
IDL> print, stregex(obj, '\+')
9
Documentation:
STREGEX(): http://www.harrisgeospatial.com/docs/stregex.html
Regular Expressions: http://www.harrisgeospatial.com/docs/learning_about_regular_ e.html#strings_3486979161_298753
STRMATCH(): http://www.harrisgeospatial.com/docs/strmatch.html#S_8200403 01_679108
-Jeff
|
|
|
Re: checking a special character in a single string [message #93170 is a reply to message #93169] |
Thu, 05 May 2016 09:15   |
Burch
Messages: 28 Registered: December 2013
|
Junior Member |
|
|
On Thursday, May 5, 2016 at 11:08:25 AM UTC-5, Jeff B wrote:
> On Thursday, May 5, 2016 at 9:28:57 AM UTC-5, Sapna Mishra wrote:
>> Hello all,
>>
>> I have a string say:
>> obj='J165248.4+363212.5'
>>
>> I want to know the place where my this + sign has come say here at 10th place .
>>
>> I did:
>> n=where(strmatch(obj,'+*',/FOLD_CASE) EQ 1)
>>
>> but it is simply giving me n=1.
>>
>> can any one tell how to proceed ?
>>
>> Also if i want to remove all the numbers after '.' (decimal) how to do?
>> with strjoin+strsplit it is simply removing decimal sign and clubbing all numbers together. I don't want numbers after decimal how to do???
>
> STRMATCH() doesn't give the location of the search string within the input. It simply returns 1 or 0 based upon whether or not the search string is in the input. Also, when I run your code I get n = -1. To get n=1 the search string for STRMATCH() needs to be '*+*'.
>
> Regardless, if you're looking for the location within the input, then the function you want is STREGEX().
>
> IDL> obj='J165248.4+363212.5'
> IDL> print, stregex(obj, '\+')
> 9
>
> Documentation:
> STREGEX(): http://www.harrisgeospatial.com/docs/stregex.html
> Regular Expressions: http://www.harrisgeospatial.com/docs/learning_about_regular_ e.html#strings_3486979161_298753
> STRMATCH(): http://www.harrisgeospatial.com/docs/strmatch.html#S_8200403 01_679108
>
> -Jeff
Forgot to add:
You can use STRMID() to extract a substring.
IDL> print, strmid(obj, 0, 7)
J165248
https://www.harrisgeospatial.com/docs/strmid.html#S_82004030 1_1074010
-Jeff
|
|
|
|
Re: checking a special character in a single string [message #93172 is a reply to message #93166] |
Thu, 05 May 2016 09:37  |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
On Thu, 5 May 2016 07:28:54 -0700 (PDT), Sapna Mishra wrote:
> Hello all,
>
> I have a string say:
> obj='J165248.4+363212.5'
>
> I want to know the place where my this + sign has come say here at 10th place .
>
> I did:
> n=where(strmatch(obj,'+*',/FOLD_CASE) EQ 1)
>
> but it is simply giving me n=1.
>
> can any one tell how to proceed ?
>
IDL> obj='J165248.4+363212.5'
IDL> print,strpos(obj,'+')
9
> Also if i want to remove all the numbers after '.' (decimal) how to do?
> with strjoin+strsplit it is simply removing decimal sign and clubbing all numbers together. I don't want numbers after decimal how to do???
IDL> print,strmid(obj,0,strpos(obj,'.'))
J165248
Cheers, Heinz
|
|
|