score:9
Accepted answer
String input = "3030313535333635";
String result = "";
for(int i = 1; i < 16; i +=2 )
{
result += input[i];
}
score:12
Try this to get the every other character from the string:-
var s = string.Join<char>("", str.Where((ch, index) => (index % 2) != 0));
score:6
You can use this well-known class System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary
:)
string str = "3030313535333635";
var hex = System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary.Parse(str);
var newstr = Encoding.ASCII.GetString(hex.Value);
score:1
Code in Java Language
String input= "3030313535333635"
String output="";
for(int i=1;i<input.length();i=i+2)
{
output+=input.charAt(i).toString();
}
System.out.println(output);
score:3
Using a StringBuilder
to create a string will save resources
string input = "3030313535333635";
var sb = new StringBuilder(8); // Specify capacity = 8
for (int i = 1; i < 16; i += 2) {
sb.Append(input[i]);
}
string result = sb.ToString();
Source: stackoverflow.com
Related Articles
- How to delete every 2nd character in a string?
- List or Array of String Contain specific word in Html Source Code
- C# - code to order by a property using the property name as a string
- Number of occurrences of a character in a string
- LINQ: String.Join a list but add a character to that string beforehand
- Why is my code doing lazy loading even after I turned it off at every possible point?
- How to get Max String Length in every Column of a Datatable
- Combine similar character in string in C#
- .NET String parsing performance improvement - Possible Code Smell
- Using LINQ to delete an element from a ObservableCollection Source
- Space character at the end of a string when saving to the database
- LINQ Source Code Available
- Trimming duplicate characters with single character in string
- Efficient way to unindent lines of code stored in a string
- .NET 4 Code Contracts: "requires unproven: source != null"
- LINQ: Get first character of each string in an array
- The given value of type String from the data source cannot be converted to type int of the specified target column
- How to replace a character in string using LINQ
- Sort list where specific character exists within string
- Elegant way to add a specific character after each char in a string
- C# String Splitting of a path to get every sub path
- creating Linq to sqlite dbml from DbLinq source code
- How to use LINQ to get last string in list<string> which has character 'P' in second position in string?
- delete everything from List<string> with specific string
- C# .How to make sure, that the end result of ordering a list of objects by a string property is the same on every computer
- Entity Framework Code First String Comparison with Oracle Db
- Get First 6 character from string which is distinct
- Match first character of a word in a String List with Linq
- linq to entities changing database connection string in code
- I can't get pagination to show up in every page on a GridView with a list as source
- Simple XML parsing with LINQ
- Deleting elements from dictionary
- How to use XDocument and Linq to read in a list of parent attribute concatenated with child comment
- Split a string in a linq select expression
- Create a generic method where a expression can be passed as parameter to make dynamic queries
- How to dynamically build and return a linq predicate based on user input
- Linq GROUP BY and SUM nullable long
- Creating nested child entities
- C# Entity Framework return list from nested object
- Slow LINQ missing from list query
- SQL code to join to, and sum data in, a table referenced by comma delimited keys
- Linq Join To View Without Materializing Until Filtered
- Linq access property by variable
- How to get minimum from multiple date columns in linq?
- mongoDB run queries just like as SQL !
- In Entity Framework Core, with one query, how do I select objects by the order of a parent object?
- SQL not in - LINQ
- Generic List to EntitySet Conversion
- How can I get LINQ to return the object which has the max value for a given property?
- Use generics to make a method work for any data type