
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to return the first unique character without using inbuilt functions using C#?
Create an empty new array of length 256, traverse through the entire string character by character and increment the value in the new array. At the end traverse the entire array and return the first character that has value 1.
Example 1
aabccd -→2 1 2 1 → Return the first character which is having count 1. That is b by subtracting with the ascii values.
Example 2
using System; namespace ConsoleApplication{ public class Arrays{ public char ReturnCharacterOfFirstUniqueCharachter(string s){ int index = -1; int[] arrayValues = new int[256]; for (int i = 0; i < s.Length; i++){ int value = s[i] - 'a'; arrayValues[value] += 1; } for (int i = 0; i < s.Length; i++){ int value = s[i] - 'a'; if (arrayValues[value] == 1){ index = i; break; } } return s[index]; } } class Program{ static void Main(string[] args){ Arrays a = new Arrays(); Console.WriteLine(a.ReturnCharacterOfFirstUniqueCharachter("bbookisgreat")); Console.ReadLine(); } } }
Output
k
- Related Articles
- How to return the index of first unique character without inbuilt functions using C#?
- How to find the missing number and the repeated number in a sorted array without using any inbuilt functions using C#?
- Python program to count upper and lower case characters without using inbuilt functions
- Count upper and lower case characters without using inbuilt functions in Python program
- What are the different ways to find missing numbers in a sorted array without any inbuilt functions using C#?
- Find the index of the first unique character in a given string using C++
- Golang Program to Convert Char Type Variables to Int Using Inbuilt Functions
- How to find a unique character in a string using java?
- Find the first repeated character in a string using C++.
- PHP – How to return the character count of a string using iconv_strlen()?
- Find first repeating character using JavaScript
- PHP – How to return character by Unicode code point value using mb_chr()?
- Generating a unique random 10 character string using MySQL?
- First Unique Character in a String in Python
- First non-repeating character using one traversal of string in C++

Advertisements