Raised This Month: $51 Target: $400
 12% 

How to check letters and words in sentences?


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-23-2023 , 18:16   Re: How to check letters and words in sentences?
Reply With Quote #11

Not sure I understand, but if you're asking if you can replace individual characters, yes you can. You just find the position of the chars you want to replace and increment or decrement as needed.

You also have the replace string natives.

PHP Code:
new szSource64 ] = "May I please have a warm beer?";

new 
iFindPos strfindszSource "warm" );

szSourceiFindPos ] = 'c';
szSourceiFindPos ] = 'o';
szSourceiFindPos ] = 'l';
szSourceiFindPos ] = 'd';

server_printszSource ); 
__________________
Bugsy is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 06-24-2023 , 13:57   Re: How to check letters and words in sentences?
Reply With Quote #12

Not exactly. There are letters, for example, whose position in the word differs and takes a different encoding of the bytes. Therefore, I want to specify the shape of the byte before the letter that I specified
What i try :
PHP Code:
                for (new 0sizeof(said_to_utf8); += 3)// Each character contains 3 bytes
                
{
                    
                    if ((
said_to_utf8[i] == 0xEF) && (said_to_utf8[i+1] == 0xBB ))
                    {
                        
//Check the third byte of the character "0x9F"
                        
if (sizeof(said_to_utf8) && said_to_utf8[i+5] == 0x9F
                        {
                            
// The character before the current character 
                            
if (>= 0)
                            {
                                new 
byteBefore1 said_to_utf8[3];
                                new 
byteBefore2 said_to_utf8[2];
                                new 
byteBefore3 said_to_utf8[1];
                                
                                
client_print(0print_chat"(debug1) 1) %d | 2) %d | 3) %d"byteBefore1byteBefore2byteBefore3)
                            
                            }
                
                            
// The character after the current character
                            
if (sizeof(said_to_utf8))
                            {
                                new 
byteAfter1 said_to_utf8[6];
                                new 
byteAfter2 said_to_utf8[7];
                                new 
byteAfter3 said_to_utf8[8];
                                
client_print(0print_chat"(debug2) 1) %d | 2) %d | 3) %d"byteAfter1byteAfter2byteAfter3)
            
                            }
                        }
                    }
                } 
I didn't get results (maybe the method is wrong I'm not sure..)
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-24-2023 , 14:06   Re: How to check letters and words in sentences?
Reply With Quote #13

Can you provide an example?

Source = "Hello Test"
Outcome = "Goodbyte Test"

or

Source = 0xFF 0x80 0x55 0x22
Outcome = 0x80 0x55 0x22 0x00

Once I fully understand I can likely make it happen.
__________________

Last edited by Bugsy; 06-24-2023 at 14:39.
Bugsy is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 06-24-2023 , 15:01   Re: How to check letters and words in sentences?
Reply With Quote #14

Do you want it in Arabic?
Source = "ﺎﺒﺣﺮﻣ"
to be = "ﺎﻋﺍﺩﻭ"
should save"Encode in UTF-8-BOM"
So:
Source be like : "ï»؟ï؛ژï؛’ï؛£ï؛®ï»£" ===> مرحبا ===> Hello
to be : "ï»؟ï؛ژﻋï؛چï؛©ï»Â*" ==> وداعا ==> Goodbye
Quote:
Source = "ﺎﺒﺣﺮﻣ"
to be = "ﺎﻋﺍﺩﻭ"
For me here, when I read thes words up, it gives the writing upside down from left to right, but it must be really like this in order to get a good result inside the screen (as if it were a trick or a hack or something like that)
Because when I want to write it in programs that support the Arabic language, for example, or websites, or in this forum or others, it is much easier and more correct than that

The Arabic language is not supported properly within the game screen
Sorry, This is why it is difficult to give an example
What I do is reverse the letters and words from left to right and then replace the letters with what suits their shape according to their position within the word (Isolated - End - Middle - Beginning)
I think fixing it by bytes makes more sense.
Some sites that I use to decode the letters:
https://www.compart.com/en/unicode/bidiclass/AL
https://en.wikipedia.org/wiki/Arabic_script_in_Unicode
https://mothereff.in/utf-8#%EF%BB%A3
Attached Thumbnails
Click image for larger version

Name:	Capture.PNG
Views:	32
Size:	11.9 KB
ID:	201027  
Attached Files
File Type: txt rtl1.txt (18 Bytes, 15 views)
File Type: txt rtl2.txt (18 Bytes, 17 views)
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-24-2023 , 16:10   Re: How to check letters and words in sentences?
Reply With Quote #15

Again, I can likely do it but I don't understand what you are trying to do. If you can somehow convey that using an English example, I can likely help.

Let's take the language out of the conversation if possible. Maybe something like "find byte position 2, replace with X. Replace the next byte with Y. Skip a byte and replace the following byte with Z."
__________________

Last edited by Bugsy; 06-24-2023 at 16:12.
Bugsy is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 06-24-2023 , 17:23   Re: How to check letters and words in sentences?
Reply With Quote #16

If you mean the English language, it is somewhat different because the number of bytes in it is 1 for each letter

I will try to explain more:
Quote:
for (new i = 0; i < sizeof(said_to_utf; i++)//
{
To calculate the bytes
Quote:
if (said_to_utf8[i] == 0xEF && (said_to_utf8[i+1] == 0xBB || said_to_utf8[i+1] == 0xBA))) {
Here the first and second bytes of each character in words are specified .. that Arabic has 3 bytes per letter ..Only the third byte changes
So I want to check the third byte of one of the characters I'm looking for and replace it with another byte.
Quote:
if (said_to_utf8[i+2] == 0x9F)
{
said_to_utf8[i+2] = 0x9E;
}
{
But it is missing a condition and it must not be another character before it being set for me to replace it

So what I thought was to subtract 3 bytes from "i" to get it
Quote:
if (i - 3 >= 0)
{
new byteBefore = said_to_utf8[i - 3];

if (byteBefore == 0x8E || byteBefore == 0x8B) {
said_to_utf8[i+2] = 0x9E;

client_print(0, print_chat, "(debug) before the letter ")
}

}
But I didn't succeed in that maybe wrong way..

P.s:
I am not trying to replace a letter or word with another letter or word , I just want to replace the byte of the letter according to its shape and position in the word.

If we were to apply the example to your data it would become:
Quote:
// Source = 0xFF 0x80 0x55 0x22
PHP Code:
        for (new 0sizeof(said_to_utf8); i++)// Source = 0xFF 0x80 0x55 0x22
        
{
            if (
said_to_utf8[i] == 0x55)
            {
                if (
>= 0)
                {
                    new 
byteBefore said_to_utf8[1];
                        
                    if (
byteBefore == 0x80) {
                            
                        
                        
said_to_utf8[i] = 0xXX//EXAMPLE
                    
}
                }
            }
        } 
Sorry for not explaining well
__________________

Last edited by abdobiskra; 06-24-2023 at 17:31.
abdobiskra is offline
Send a message via Skype™ to abdobiskra
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-24-2023 , 18:32   Re: How to check letters and words in sentences?
Reply With Quote #17

Ok so here's what I understand.

- Each character is 3 bytes
- You want to check the first two bytes, and if they match what you're looking for, check if the 3rd is X before changing to Y

Reviewing your code here and now that I understand a bit better, maybe your problem was your for-loop is incrementing by 1 byte per iteration instead of incrementing by 3.

PHP Code:
#include <amxmodx>

public plugin_init() 
{
    new 
i;
    
    
//5 letters based on your explanation
    
new said_to_utf8[] = 
    {  
        
0xEF 0xBB 0x9F ,    //239 187 159
        
0xEF 0xBB 0x9F 
        
0xEF 0xBB 0x9F 
        
0xEF 0xBB 0x9F 
        
0xEF 0xBB 0x9F
    
};
    
    
//Output the original data
    
for ( new <= charsmaxsaid_to_utf8 ) ; i+= )
        
server_print"Original %d %d %d" said_to_utf8] ,  said_to_utf81] , said_to_utf8] );
        
    do 
    {
        
//If byte 1 is 0xEF and byte 2 is 0xBB then..
        
if  ( ( said_to_utf8] == 0xEF ) && ( said_to_utf8] == 0xBB ) )
        {
            
//if the third byte is 0x9F, change it to 0x9E
            
if ( said_to_utf8] == 0x9F )
                
said_to_utf8] = 0x9E;
        }
    } 
    while ( ( 
+= ) < charsmaxsaid_to_utf8 ) )
    
    
//Output the changed data
    
for ( new <= charsmaxsaid_to_utf8 ) ; i+= )
        
server_print"Changed %d %d %d" said_to_utf8] ,  said_to_utf81] , said_to_utf8] );

Output:
Code:
Original 239 187 159
Original 239 187 159
Original 239 187 159
Original 239 187 159
Original 239 187 159

Changed 239 187 158
Changed 239 187 158
Changed 239 187 158
Changed 239 187 158
Changed 239 187 158
__________________

Last edited by Bugsy; 06-24-2023 at 21:46.
Bugsy is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 06-25-2023 , 00:10   Re: How to check letters and words in sentences?
Reply With Quote #18

Yes, now I want to get the last byte of the character before the character I specified earlier
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-25-2023 , 00:18   Re: How to check letters and words in sentences?
Reply With Quote #19

You're losing me... So then just subtract 3 from the index, and increment by 2?
__________________

Last edited by Bugsy; 06-25-2023 at 00:19.
Bugsy is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 06-30-2023 , 08:38   Re: How to check letters and words in sentences?
Reply With Quote #20

Thank youu Bugsy
I had some confusion in my code I think this method is enough
PHP Code:
                        if (said_to_utf8[i+2] == 0x9F) {
                            
                            if (
sizeof(said_to_utf8)) {
                                
                                if ( 
said_to_utf8[i+5] == 0x8E) { 
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
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 14:54.


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