Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-03-26 15:40:38

madiik
Member
From: floor above Yuuta
Joined: 2015-02-26
Posts: 514

[Tool] Substring with actual "null" check!

C# is a bit bad
because that ugly language lacks to check if the string exists or not by that length
for example:

string.Substring(1,5) == "!add "

this would return an error if player chats below 5 letters

wtf C#

anyway, if you ever need to: here's my workaround.

namespace Extension
{
    public static class StringExtension
    {
        public static string GetSubstring(this string s, int beg, int end = 0)
        {
            if (end != 0 && s.Substring(beg, end) != null)
                return s.Substring(beg, end);
            else if (end == 0 && s.Substring(beg) != null)
            {
                return s.Substring(beg);
            }
            else
                return null;
        }
    }
}

shh i have returned

Offline

#2 2015-03-26 18:12:20

912468
Member
Joined: 2015-02-21
Posts: 212
Website

Re: [Tool] Substring with actual "null" check!

Can't you just use this:

try
{
    string.Substring(1, 5);
}
catch { }

vF0MA5o.png

Offline

#3 2015-03-26 18:30:34

madiik
Member
From: floor above Yuuta
Joined: 2015-02-26
Posts: 514

Re: [Tool] Substring with actual "null" check!

912468 wrote:

Can't you just use this:

try
{
    string.Substring(1, 5);
}
catch { }

In this case, it would give you an error too and NOT even do it.
I've done this before, "try" and "catch." Still errored with Substring.


shh i have returned

Offline

#4 2015-03-26 19:13:37, last edited by Different55 (2015-03-26 19:14:20)

Different55
Forum Admin
Joined: 2015-02-07
Posts: 16,575

Re: [Tool] Substring with actual "null" check!

It's been way too long since I did anything in C# so I might be missing something but why not just assign null to the variable inside the catch statement instead of leaving the catch statement empty?


"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto

Offline

Wooted by:

#5 2015-03-26 23:27:40

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: [Tool] Substring with actual "null" check!

Can't you just do this:

if (string.StartsWith("!add"))
{}

but okie

try
{
    string.Substring(0, 5);
}
catch (Exception excep)
{
    try
    {
        string.Substring(0,4) //heres another cmd
    }
    catch(Exception except)
    {
      string.Substring(0,2)  //oh hi dere im anuter commund
    }
}

ALL MORE LENGTH ON TOP!
in bot words,
Top to below length number


http://i.imgur.com/bjvgH5L.png?1

Offline

realmaster421427408860487925

Board footer

Powered by FluxBB

[ Started around 1732498691.5543 - Generated in 0.042 seconds, 14 queries executed - Memory usage: 1.42 MiB (Peak: 1.53 MiB) ]