Tags down


How to sort strings alphabetically that separated by special character like comma in asp.net C#

By : JeffEhmann
Date : September 14 2020, 04:00 PM
I hope this helps . In C#, how can I sort strings that separated by special character, like "," , This can be done within a single line of code using linq:
code :
var result = string.Join(",", source.Split(",").OrderBy(s => s));

Share : facebook icon twitter icon

Sort comma separated list Alphabetically PHP

By : Tushar
Date : March 29 2020, 07:55 AM
like below fixes the issue I am pasting you a snippet what it is doing:
Splicing string Remove blank spaces on each element Remove empty elements Sorting array Printing the result
code :
$xyz = "Europe, France, Italy, Spain, UK, US,Nordic, West Europe, Belgium, Luxembourg, Netherlands, Sweden,US,Asia, Europe, Israel, North America, India,North America, , China, Hong Kong,West North Central, West South Central,UK,East South Central,Middle Atlantic, Greater China, Malaysia, Singapore, Taiwan, Middle Atlantic, Global, Australasia, Central and East Europe";
$array = array_filter(array_map('trim', explode(',', $xyz)));
$array = implode(', ', $array);

How do I sort an Array with comma separated strings in PHP?

By : cathy
Date : March 29 2020, 07:55 AM
I wish this help you it's my first post here, I'm a beginner and I hope you'll go easy on me. I searched for an answer, and read some semi-related questions. I've been stuck on this for a couple days and I really am very confused. Apologies if the double barrelled is a faux pas, it seemed less sensible to write this as two seperate questions. I'm new to programming and I had never heard of this website until yesterday, I hope to be a contributing part of what seems to be an awesome community.
code :
$arraybase = array(
    2 => 'string1,10',
    7 => 'string2,15',
    10 => 'string3,3',
    11 => 'string4,7',
function mapping($data){
    $array1 = array();//for first csv
        $array1[$k[1]] = $value;
    $array2 = array_map(function($value){//for second csv
        return preg_replace('/,\d+$/','',$value);

    return array("csv1"=>$array1,"csv2"=>$array2);
$result = mapping($arraybase);
    [csv1] => Array
            [15] => string2,15
            [10] => string1,10
            [7] => string4,7
            [3] => string3,3

    [csv2] => Array
            [15] => string2
            [10] => string1
            [7] => string4
            [3] => string3


Sort an array of strings alphabetically, numerically then by special characters

By : jus kulit manggis
Date : March 29 2020, 07:55 AM
hop of those help? Here's my stab at what you're looking for. I think it's a bit cleaner than what you have:
code :
Array.prototype.naturalSort = function() {
  var stringRE = /^[A-Za-z]+$/
  var numberRE = /^[\d]+$/
  return this.sort(function(a, b) {
    var aIsString = stringRE.test(a);
    var bIsString = stringRE.test(b)
    var aIsNumeric = numberRE.test(a);
    var bIsNumeric = numberRE.test(b);
    if (aIsString && bIsString) {
      return a.localeCompare(b);
    } else if (aIsNumeric && bIsNumeric) {
      return parseInt(a, 10) - parseInt(b, 10);
    } else if (aIsString && bIsNumeric) {
      return -1;
    } else if (aIsNumeric && bIsString) {
      return 1;
    } else if (aIsString || aIsNumeric) {
      return -1;
    } else if (bIsString || bIsNumeric) {
      return 1;
    } else {
      return a.localeCompare(b);

var chars = ["T","D","I","C","Y","O","4","K","N","800","S","1","V","(","10","'","`","B","M","[","-"," ","J","U","H","G","R","E","P"];

// ["B", "C", "D", "E", "G", "H", "I", "J", "K", "M", "N", "O", "P", "R", "S", "T", "U", "V", "Y", "4", "1", "10", "800", " ", "-", "'", "(", "[", "`"]

Sort strings/words alphabetically separated by comma within a column in SQL (entire column)

By : user1703178
Date : March 29 2020, 07:55 AM
I wish this helpful for you Here is an Oracle solution using Common Table Expressions (CTEs) to break the problem down. Not sure if this will help, but maybe it will give you an idea or a starting point that you can apply to your environment.
code :
SQL> -- Set up original data set
SQL> with bird_tbl(id, unsorted_list) as (
     select 1, 'Sparrow, Eagle, Crow' from dual union all
     select 2, 'Woodpecker, Sparrow' from dual union all
     select 3, 'Crow, Eagle' from dual
   -- Split the list into a row for each element
   split_tbl(id, bird) as (
     select id, regexp_substr(unsorted_list, '(.*?)(, |$)', 1, level, null, 1)
     from bird_tbl
     connect by level <= regexp_count(unsorted_list, ', ')+1
       and prior id = id
       and prior sys_guid() is not null
   -- select * from split_tbl;
   -- Rebuild the sorted row
   select id, listagg(bird, ', ')
     within group (order by bird) sorted_list
     from split_tbl
     group by id;

---------- --------------------
         1 Crow, Eagle, Sparrow
         2 Sparrow, Woodpecker
         3 Crow, Eagle
with split_tbl(<your_primary_key>, <your_column_name>) as (
     select <your_primary_key>, regexp_substr(<your_column_name>, '(.*?)(, |$)', 1, level, null, 1)
     from <your_table_name>
     connect by level <= regexp_count(<your_column_name>, ', ')+1
       and prior <your_primary_key> = <your_primary_key>
       and prior sys_guid() is not null
   -- select * from split_tbl;
   -- Rebuild the sorted row
   select <your_primary_key>, listagg(<your_column_name>, ', ')
     within group (order by <your_column_name>) sorted_list
     from split_tbl
     group by <your_primary_key>;

Sort each row of character strings alphabetically in R

By : user3036221
Date : March 29 2020, 07:55 AM
I wish this help you I've looked around and can't seem to find a decent way to solve this issue. , With dplyr, you can try:
code :
df %>%
 rowwise() %>%
 mutate(names = paste(sort(unlist(strsplit(names, ", ", fixed = TRUE))), collapse = ", "))

  names                       var1  var2
  <chr>                      <dbl> <dbl>
1 John D., Josh C., Karl H. -0.226  19.9
2 Bob S., John D., Tim H.    0.424  24.8
3 Amy A., Art U., Wes T.     1.42   25.0
4 John D., Josh C., Karl H.  5.42   20.4
df <- data.frame(names, var1, var2,
                 stringsAsFactors = FALSE)
Related Posts Related Posts :
  • SQL Command Parameter cannot covert string to int
  • Azure Notification Hub example to register a device and receive a notification
  • Disabed element shown as enabled in Selenium C#
  • Html.listboxfor() how to capture event on change/add item - Jquery MVC (C#)
  • c# Accessing my array inside a class constructor
  • How to first 'Split a string to an Array' then 'Add something to that Array'? || C# Console App
  • IEnumerable of Tuple of string of string
  • Why don't I get a warning about possible dereference of a null in C# 8 with a class member of a struct?
  • Visual Studio 2019: how to disable specific CodeAnalysis messages in .editorconfig?
  • Pass ID to controller on prev or next
  • What are the difference using app.run and app.useendpoints in asp.net-core?
  • Why string Method(Object object) may not match Func<Object, string> delegate type?
  • Check inside loop if *txt file has been created
  • C# retry logic While loop
  • Convert object {object[]} to string[]
  • Difference between initialize a string to "" or to "".ToString() - Which one should I use?
  • How to make the console wait but then continue without pressing a Key?
  • extract text in rich text format from range
  • how to handle 1000 concurrent user requests per second in asp.net web api
  • In C# How to get Windows Credentials from credential manager
  • Override default value of null conditional operator
  • How to fix override ToString method
  • System.IO.FileNotFoundException when creating EF migrations on .net core
  • Login limit attempts in C#
  • Loop into ListView elements
  • Changing Blazor folder gives me "Cannot find the fallback endpoint"
  • creating class from JSON with different types of a node
  • How to define models for Database tables in C# without using Linq To DB?
  • Understanding Identityserver4 with Identity (cookies/tokens, server architecture)
  • How to Deserialize a JSON into a list using SIMPLE JSON?
  • another option instead using AsEnumerable() in linq EF, when using custom method in linq
  • Parameterized query that returns TEXT column(s) always returns zero for INT columns
  • Why format is not working while appending zeros?
  • SqlConnection string
  • Entity Framework Core Update Database - Code First Approach Without Migration
  • Unity Update Method
  • Custom Middleware is causing Blazor Server-side page to stop working
  • Declaring hex number: The name 'B9780' does not exist in the current context
  • Invalid cast from 'System.Int32' to Enum using reflections
  • Why does my webrequest line need updating? (error (426) Upgrade Required )
  • How to generate Key and Key IV aes in C#
  • How can I display view inside content control in wpf
  • How can I wait for form2 to finish?
  • Is Application.DoEvents() a form of Multitasking?
  • In C#, how can I see if the first character in an account is a specific value?
  • C# Determine if a char at index is between two characters in a string
  • C# - Winform Timer - Disposing and emptying the timer
  • if else condition in Regex c# and return constant value
  • Ternary operator for 3 conditions
  • Fineuploader with Azure, Empty image problem
  • How do I unit test the event raised by class under test?
  • How to set up .net core service that uses a generic repository
  • ASP.NET Core 3.0 Endpoint Routing doesn't work for default route
  • use gmail API token on localhost and hosting at the same time
  • Try-catch FormatException
  • why do sql procedure retuns 0 rows when called from applciation?
  • .Net core 3: The namespace internal does not exist in Microsoft.Extensions.Logging.Internal
  • how to interpolate a variable into string method
  • I want to instantiate an object at the location of another object which is destroyed
  • How to display full path of ALL currently running process in C#?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk