![]() |
Deleting chracters
can someone please tell me how to delete characters from a string, say like if i have a string called 'hello world' i want all the 'o' to be deleted so i end up with 'hell wrld' and how do i print the same string in uppercase 'hello world' 'HELLO WORLD' in sim8086, please i need to know how to do it asap.
|
Re: Deleting chracters
Point to the character in the string you want to remove, replace it with the next character in the string, then move to the next character, replace that one with the one after it, and so on. If the string is null terminated, don't forget to add a null byte.
To convert an ASCII character to uppercase, simply subtract 32 (The difference between a and A on the ascii table). |
Re: Deleting chracters
how would i go about doing that? im fairley new to assembly
this is the code to ask the user to enter a string :
mov AH, 63this code prints the string to screen :
mov AH, 64 |
Re: Deleting chracters
Quote:
|
Re: Deleting chracters
Quote:
Assuming that he's using ASCII, one way of doing it faster would be to populate a 256-byte table, point DS:(E)BX at this table, and use XLATB. This eliminates checks for range, so you can quickly map one character to another. If you want strict ASCII with no support for the so-called 'high ASCII', you can cut the table by half, and mask against 07Fh before the lookup; this'll save a whopping 128 bytes. Just loop through the string, doing a lookup for each byte until you hit the end. Presumably, your string is null-terminated, but if it's not, you'll have a length count that you can load into (E)CX before you start. |
Re: Deleting chracters
most of the charactes may already be capitals, depending on what the user types in so i just need the non caps to be capital, and how do i delete letters from a string, for example if i have a string called hello i want to delete the 'll'
|
Re: Deleting chracters
Quote:
First is to subtract from the character values. In ASCII, the uppercase letters are values 65 through 90 (decimal), and the lowercase letters are 97 through 122. The order is purely alphabetical, so 65 is 'A', 66 is 'B', and so on. Thus, if you subtract 32 from the value of a lowercase letter, it becomes an uppercase one. My elaboration on Benoit's post was simply pointing out you need to first make sure it's a lowercase letter. If it's something else, you will get unpredictable results, so you can do something like this (NASM-style syntax, but you can adapt it): :
mov cx, length ; load the string lengthThe second option is to load a table (either 256 or 128 bytes in size) with the 'convert to' values. Then you do a lookup to convert a value into another value, or more specifically, use value A as an index into the table to fetch value B. In your specific case, you'd have each value equal its own index, except for the lowercase letter indices; these would be equal to their uppercase counterparts. Thus, index 10 would store the value 10, index 65 would hold 65, but index 97 would also hold 65. Get it? Then you use the XLATB (table lookup translation) instruction, like so: :
mov cx, length ; load the string lengthThere is a line in red there. This can be deleted if your table is 256 bytes in size, but if you want strict conformance with ASCII, and don't care about 'extended ASCII', you can cut the table to 128 bytes. If you do this, the line in red will prevent you from indexing past the end of your lookup buffer. Quote:
|
Re: Deleting chracters
Such an useless argument...
Anyway, just AND the byte (assuming it's ANSI) by 0xDF, that should force it go to uppercase and that is faster than any of the aforementioned arguments. After doing so just do a REP SCASB (again, assuming it's ANSI) until you find the character you're looking for then just use REP MOVSB to copy over it. |
Re: Deleting chracters
Quote:
Quote:
If the number of letters in the alphabet was a power of two, a simple AND could work (assuming the values were mapped appropriately). However, since the number of letters is 26 (NOT a power of two), it won't work. It requires either a subtraction or a table lookup, and the former first requires range checking to ensure you don't change anything except lowercase letters. |
| All times are GMT -5. The time now is 12:39 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC