I have a string like 1,2,3,4,5,6,7,8,9,10, and is there a way to split it into two strings, below:
String input: 1,2,3,4,5,6,7,8,9,10 output String 1: 1-3, 4,6 output String 2: 5, 7-10 I don't know how to do "-". Thanks, |
Administrator
|
Look up the CHAR.SUBSTR, CHAR.INDEX and CONCAT functions.
a LOOP might come in handy too. Perhaps you should describe the 'rule' governing your desired output? It appears to be rather arbitrary and unsystematic.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Suppose there is a number sequence, 1,2,3,4,5,6,7,8,9,10 and I could divide it into the following two group;
group 1: 1, 2, 3, 4, 6 group 2: 5, 7, 8, 9, 10 I want it to organize in the following way, where when numbers are adjacent, using "-". group 1: 1-4, 6 group 2: 5, 7-10 Could anyone know how to achieve this? Thanks, |
Administrator
|
In response to your first post in this thread, David Marso wrote:
"Perhaps you should describe the 'rule' governing your desired output? It appears to be rather arbitrary and unsystematic." I think that comment still applies after this most recent post. What is the 'rule'? HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Thanks for the reply.
The rule is to group the numbers that are next to each other together. As the example I mentioned, input: 1,2,3,5,6,7,8,9,10 output: 1-3,5-7,8-10 Thanks again. |
I think he means in triplets or threes. What happened to 4?
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of albert_sun Sent: 05 July 2016 01:02 To: [hidden email] Subject: Re: How to split a string Thanks for the reply. The rule is to group the numbers that are next to each other together. As the example I mentioned, input: 1,2,3,5,6,7,8,9,10 output: 1-3,5-7,8-10 Thanks again. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-split-a-string-tp 5732329p5732591.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Not necessarily to be in threes. I would like to group numbers that are next to each other with "-", rather than list all numbers. Take another example, if I have numbers "2,3,4,6,8,9,10,11,15",is there a way to write a syntax to have the output as 2-4,8-11,15? This will simply the representation of these numbers (2-4 to represent 2,3,4 for example).On Tue, Jul 5, 2016 at 4:28 PM, John F Hall [via SPSSX Discussion] <[hidden email]> wrote: I think he means in triplets or threes. What happened to 4? |
Administrator
|
In reply to this post by albert_sun
Ah, okay. Sorry, I misunderstood. I thought you were asking how to take this input string:
1,2,3,4,5,6,7,8,9,10 and produce these two output strings: group 1: 1, 2, 3, 4, 6 group 2: 5, 7, 8, 9, 10 But I see that you are asking how to convert the two strings above (for groups 1 and 2) into this: group 1: 1-4, 6 group 2: 5, 7-10 Are the numbers all whole numbers? What is the range of possible values? How general a solution do you need?
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
Why? You end up with a string variable which is useless for any sort of analytics. Maybe read up on some basic programming concepts, make an honest effort to solve your own problem. When you fail post your stab at solving the problem and maybe someone will step in and solve your issue. I'm not writing any code for you until you make an effort to sort it yourself. And you never responded to my original request for clarification which makes the likelihood of my responding to whatever you post later somewhat less likely. --
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
First step is to create an outline of a possible solution.
You need to first parse the string into constituent pieces (probably into a VECTOR yes RTFM!). Then need to iterate over the vector and query the status of successors... LOOP ;-) That is as far as I'm going to take you now. You still end up with useless shit anyway ;-) ---
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
I think what he wants is a separate string for each contiguous
sequence, so if there is a number missing, the previous one constitutes the end of the string and the next one the start of a new one. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso Sent: 05 July 2016 15:32 To: [hidden email] Subject: Re: How to split a string First step is to create an outline of a possible solution. You need to first parse the string into constituent pieces (probably into a VECTOR yes RTFM!). Then need to iterate over the vector and query the status of successors... LOOP ;-) That is as far as I'm going to take you now. You still end up with useless shit anyway ;-) --- David Marso wrote > Why? You end up with a string variable which is useless for any sort > of analytics. > Maybe read up on some basic programming concepts, make an honest > effort to solve your own problem. When you fail post your stab at > solving the problem and maybe someone will step in and solve your > issue. I'm not writing any code for you until you make an effort to sort it yourself. > And you never responded to my original request for clarification which > makes the likelihood of my responding to whatever you post later > somewhat less likely. > -- > Bruce Weaver wrote >> Ah, okay. Sorry, I misunderstood. I thought you were asking how to >> take this input string: >> >> 1,2,3,4,5,6,7,8,9,10 >> >> and produce these two output strings: >> >> group 1: 1, 2, 3, 4, 6 >> group 2: 5, 7, 8, 9, 10 >> >> But I see that you are asking how to convert the two strings above >> (for groups 1 and 2) into this: >> >> group 1: 1-4, 6 >> group 2: 5, 7-10 >> >> >> Are the numbers all whole numbers? What is the range of possible >> How general a solution do you need? >> >> albert_sun wrote >>> Thanks for the reply. >>> >>> The rule is to group the numbers that are next to each other together. >>> As the example I mentioned, >>> >>> input: 1,2,3,5,6,7,8,9,10 >>> output: 1-3,5-7,8-10 >>> >>> Thanks again. ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-split-a-string-tp 5732329p5732596.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |