comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » checking a special character in a single string
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
checking a special character in a single string [message #93166] Thu, 05 May 2016 07:28 Go to next message
Sapna Mishra is currently offline  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 Go to previous messageGo to next message
Burch is currently offline  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 Go to previous messageGo to next message
Burch is currently offline  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 #93171 is a reply to message #93170] Thu, 05 May 2016 09:30 Go to previous messageGo to next message
Sapna Mishra is currently offline  Sapna Mishra
Messages: 66
Registered: December 2015
Member
> 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


Yeah this step can only be done if you know where is the decimal point is like in my case i have two decimal points.... so i want string to break in two and remove decimal point from both.
Thanks for the help Jeff.....stregex works..
Re: checking a special character in a single string [message #93172 is a reply to message #93166] Thu, 05 May 2016 09:37 Go to previous message
Heinz Stege is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Visualize a Radar image with ENVI
Next Topic: Tool for converting FK4/FK5

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:14:36 PDT 2025

Total time taken to generate the page: 0.00496 seconds