Search
Latest topics
Who is online?
In total there are 5 users online :: 0 Registered, 0 Hidden and 5 Guests None
Most users ever online was 38 on Sun Mar 19, 2023 10:07 pm
Most Viewed Topics
[C#] String Case-Inversion
2 posters
Page 1 of 1
[C#] String Case-Inversion
"A string like this", will become, "a STRING LIKE THIS"
"A StRing LIKE this", will become, "a sTrING like THIS"
etc.
"A StRing LIKE this", will become, "a sTrING like THIS"
etc.
- Code:
public static class StringExtensions
{
public static string InvertCase(this string s)
{
var cArr = s.ToCharArray();
for (var i = 0; i < cArr.Length; i++)
{
var cInt = (int)cArr[i];
if ((cInt >= 65 && cInt <= 90) || (cInt >= 97 && cInt <= 122))
{
cInt ^= 1 << 5;
cArr[i] = (char) cInt;
}
}
return new string(cArr);
}
}
cloud9- Moderator
- Posts : 38
Join date : 2014-04-09
Age : 34
Re: [C#] String Case-Inversion
I am not an expert in C# but here is another way to do so using lambda expressions in C#
[You must be registered and logged in to see this link.]
[You must be registered and logged in to see this link.]
- Code:
using System;
using System.Linq;
class StringInversion
{
public static void Main()
{
string data = "i Am A mONkeY";
string invStr = new string(data.Select(chr => char.IsLetter(chr) ? (char.IsLower(chr) ? char.ToUpper(chr) : char.ToLower(chr)) : chr).ToArray());
Console.WriteLine(invStr);
}
}
ADS1- Script Kiddie
- Posts : 17
Join date : 2014-05-31
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Tue Feb 02, 2021 7:12 am by manas41
» SQL injection and Quote escaping
Sun Jun 28, 2015 11:42 am by ADS1
» [TUT] Chmod: Files & Permissions [TUT]
Thu Jun 04, 2015 12:45 pm by Guest
» Reaver pixiewps
Thu Jun 04, 2015 12:23 pm by voidfletcher
» How To Crash Someone's Skype in 10 SECONDS
Thu Jun 04, 2015 12:20 pm by voidfletcher
» Internet Security & IP Security (IPSec)
Mon May 18, 2015 9:00 pm by voidfletcher
» [Python] Infinite / Definite File Generator
Mon May 18, 2015 8:58 pm by ADS1
» [C#] String Case-Inversion
Mon May 18, 2015 8:57 pm by ADS1
» Rekall Memory Forensic Framework
Sat May 16, 2015 8:55 pm by ADS1