Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 12:22 AM EDT
0
the best overloaded method match for string join
error
0
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 16, 2013, 12:27 AM EDT
0
hi,
Is the error in my code? if yes than please provide inforamtion like which framework version used by u... my code is work fine for framework 3.5 and above...
0
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 12:34 AM EDT
0
framework 3.5 sir and error the best overloaded method match for string join
0
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 16, 2013, 12:37 AM EDT
0
are you include System and System.Linq name space in you code.
using System; using System.Linq;
0
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 12:43 AM EDT
0
Yes sir I am using both namespace
0
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 16, 2013, 12:47 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Oct 16, 2013, 1:17 AM EDT
0
Hi,
i checked jignesh solution it working fine for me.
you can try this also:
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace IfExample { class SortString { static void Main() {
string emp = "44,87,555,777,666"; string[] emps = emp.Split(','); var query = from no in emps orderby Convert.ToInt32(no) select no; string s = ""; foreach (String sa in query) { s += sa + ","; } Console.WriteLine(s); } } }
0
VulpesRank #55 · 29.2K reputationPosted Oct 16, 2013, 1:23 AM EDT
0
Jignesh's original solution works in .NET 4.0 or later thanks to the introduction of this new 'convenience' overload of the String.Join() method:
public static string Join(string separator,IEnumerable values)
For .NET 3.5 you have to convert to either a string[] or an object[], or do the concatenation yourself using foreach.
0
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 1:33 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 16, 2013, 12:00 AM EDT
i think you are looking solution in c#
try...
string gg = "2,55,4,3,77,9,5";
string pp = string.Join(",",gg.Split(new char[] { ',' }).OrderBy(f1 => Convert.ToInt32(f1)));
hope this will help you.
Posted Oct 16, 2013, 12:22 AM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 12:22 AM EDT
error
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 16, 2013, 12:27 AM EDT
Is the error in my code?
if yes than please provide inforamtion like which framework version used by u...
my code is work fine for framework 3.5 and above...
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 12:34 AM EDT
and error the best overloaded method match for string join
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 16, 2013, 12:37 AM EDT
using System;
using System.Linq;
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 12:43 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 16, 2013, 12:47 AM EDT
this is working fine for me.. :)
string gg = "2,55,4,3,77,9,5";
string pp = string.Join(",", gg.Split(new char[] { ',' }).OrderBy(f1 => Convert.ToInt32(f1)));
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 12:51 AM EDT
Ur code is right but it returns
string 44,87,555,777,666 to answer as
87,777,666,555
it compares87first
VulpesRank #55 · 29.2K reputationPosted Oct 16, 2013, 1:01 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 16, 2013, 1:05 AM EDT
hi,
try following code
string gg = "2,55,4,3,77,9,5";
//string pp = string.Join(",", gg.Split(new char[] { ',' }).OrderBy(f1 => Convert.ToInt32(f1)));
string emp = "";
var dd = gg.Split(',').OrderBy(f1 => Convert.ToInt32(f1));
foreach(string pp in dd)
{
emp += "," + pp;
}
emp = emp.Substring(1);
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Oct 16, 2013, 1:17 AM EDT
i checked jignesh solution it working fine for me.
you can try this also:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IfExample
{
class SortString
{
static void Main()
{
string emp = "44,87,555,777,666";
string[] emps = emp.Split(',');
var query = from no in emps
orderby Convert.ToInt32(no)
select no;
string s = "";
foreach (String sa in query)
{
s += sa + ",";
}
Console.WriteLine(s);
}
}
}
VulpesRank #55 · 29.2K reputationPosted Oct 16, 2013, 1:23 AM EDT
public static string Join
For .NET 3.5 you have to convert to either a string[] or an object[], or do the concatenation yourself using foreach.
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 16, 2013, 1:33 AM EDT
tthanks
string sort1 = "";
string sort = "";
string input = empoyee1;
string[] stringArray = input.Split(new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries);
int length = stringArray.Length;
int[] intArray = new int[length];
for (int i = 0; i < length; i++)
{
try
{
intArray[i] = Convert.ToInt32(stringArray[i]);
}
catch (Exception)
{
// ignore
}
}
Array.Sort(intArray);
foreach (int j in intArray)
{
sort = j + ",";
sort1 = sort1 + sort;
}
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts