Raised This Month: $ Target: $400
 0% 

String to int


Post New Thread Reply   
 
Thread Tools Display Modes
Xenogenetics
Member
Join Date: Jul 2007
Old 07-17-2007 , 19:13   Re: String to int
Reply With Quote #11

thats cool, I guess I will just stick with basic colors for now, I was really just doing this for practice.
Xenogenetics is offline
Vbios__
Junior Member
Join Date: Aug 2007
Location: Ukraine,Cherkassy
Old 01-08-2008 , 15:15   Re: String to int
Reply With Quote #12

how can I convert a String (for example "WOrD") to integer ,getting it from UTF-8 or ASCII char coding
__________________
sorry for my bad English

Last edited by Vbios__; 01-08-2008 at 15:18.
Vbios__ is offline
ferret
SourceMod Developer
Join Date: Dec 2004
Location: Atlanta, GA
Old 01-08-2008 , 15:28   Re: String to int
Reply With Quote #13

What exactly do you mean?

new number = String[0];
new number2 = String[1];

Each individual charactere of the string is already a number.
__________________
I'm a blast from the past!
ferret is offline
Vbios__
Junior Member
Join Date: Aug 2007
Location: Ukraine,Cherkassy
Old 01-08-2008 , 15:50   Re: String to int
Reply With Quote #14

But it is tag mistmatch! convertion from String to Int
function StringToInt can convert only integer string
__________________
sorry for my bad English
Vbios__ is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 01-08-2008 , 17:13   Re: String to int
Reply With Quote #15

How are you doing it? The way ferret said to do it works perfectly fine.

[edit]

I removed the code from before, so if you used it before, try this way. Otherwise, forget I said anything.

Code:
#include <sourcemod>

public Plugin:myinfo = 
{
    name = "text to ascii",
    author = "bl4nk",
    description = "converts text to ascii",
    version = "1.0.1",
    url = "http://www.sourcemod.net/"
}; 

public OnPluginStart()
{
    RegAdminCmd("sm_ascii", Command_Ascii, ADMFLAG_CHEATS, "sm_ascii <text>");
}

public Action:Command_Ascii(client, args)
{
    if (!args)
    {
        ReplyToCommand(client, "[SM] Usage: sm_ascii <text>");

        return Plugin_Handled;
    }

    decl String:text[192];
    GetCmdArgString(text, sizeof(text));
    
    new startidx;
    if (text[strlen(text)-1] == '"')
    {
        text[strlen(text)-1] = '\0';
        startidx = 1;
    }

    for (new i = 0; i < strlen(text); i++)
    {
        new ascii = text[startidx + i];

        PrintToChat(client, "Letter #%i's ascii code: %i", i, ascii);
    }

    return Plugin_Handled;
}
Code:
] sm_ascii pie
Letter #0's ascii code: 112
Letter #1's ascii code: 105
Letter #2's ascii code: 101
] sm_ascii lolzerific
Letter #0's ascii code: 108
Letter #1's ascii code: 111
Letter #2's ascii code: 108
Letter #3's ascii code: 122
Letter #4's ascii code: 101
Letter #5's ascii code: 114
Letter #6's ascii code: 105
Letter #7's ascii code: 102
Letter #8's ascii code: 105
Letter #9's ascii code: 99
The only problem would be with symbols whose ascii code begins with a 0. That 0 at the beginning would be dropped off because that's how integers work.

Last edited by bl4nk; 01-08-2008 at 19:47.
bl4nk is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode