How to swap two strings present in a single line(alphabetic order)?

Posted by Gudevg under C# on 4/6/2012 | Points: 10 | Views : 1718 | Status : [Member] | Replies : 14
Good day all,

I want to swap two strings in a single line based on its alphabetic order. This swapping is only applicable for the Author name not more than that.

Example:

Arun 2012, Gopi 2010, Dinesh 2012. Computer Networks, Tata McGraw Hill. 745:19-22
In this line author names Likely Arun, Dinesh, Gopi have to swap in alphabetical order and saved in a same file for reference.
OUTPUT
Arun 2012, Dinesh 2012, Gopi 2010. Computer Networks, Tata McGraw Hill. 745:19-22

How could it possible to swap exactly the string array?

Note:
Every (Multiple)author name is separated by comma(,) and end with (.) full stop

Deepakkumar G.


Responses

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Deeppakumar,

here you can use Regex.Split()


Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
Yes, using Regex.split() I could separate my Author name individually but it is possible to change the same with in a single line. Arun 2012, Dinesh 2012, Gopi 2010 . Computer Networks, Tata McGraw Hill. 745:19-22

Regards


Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
yes possible

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
Ok I will try


Regards

Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
code:

In this code u need to insert colon(:) symbol for seprate author name and others...


Dim i As String = "Arun 2012, Gopi 2010, Dinesh 2012,: Computer Networks, Tata McGraw Hill. 745:19-22"
Dim str As String = ""
Dim coll As New List(Of String)
For Each mat As Match In System.Text.RegularExpressions.Regex.Matches(i, "(.[^,.:]*?[,.])+:(.*?)", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
For Each mat1 As Match In System.Text.RegularExpressions.Regex.Matches(mat.ToString, "(.[^,.:]*?[,.])", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
coll.Add(Trim(mat1.ToString))
Next
str = mat.ToString
Next
coll.Sort()
Dim collstr As String = ""
For a = 1 To coll.Count
collstr &= coll(a - 1)
Next
i = System.Text.RegularExpressions.Regex.Replace(i, str, collstr)

Advance 'apologise' for is there any wrong in code...


Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
On that code why i am using Colon(:) means, sometimes names also comes like., a.arun 2010, dinesh.k 2012, gopi 2010.........

on that time this code not giv effictive solution. So i used Colon(:)...

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
Ji,

I compiled the task. Being thanks for your response

Regards,


Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
its okay..

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
Hi deepak,

r u got solution..?

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
Mission completed.


Regards,

Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
using regex or anything else..?

using the above code..?

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
First of all i tried it with strPara.SkipWhile(x=>x!='.').ToString(); finally completed with Regex.Match only.


Regards,

Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
ok ok...

Many places Regex will helps..

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gudevg on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
Its getting out of time. Will come back with new pobs.

Good bye,

Deepakkumar G.

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response