![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2008
Posts: 5
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 550
Rep Power: 4
![]() |
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).
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2008
Posts: 5
Rep Power: 0
![]() |
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, 63 mov BX, 0 mov CX, 25 lea DX, UserText int 33 this code prints the string to screen mov AH, 64 mov BX, 1 mov CX, Length lea DX, UserText int 33 |
|
|
|
|
|
#4 | |
|
Newbie
Join Date: Mar 2008
Posts: 5
Rep Power: 0
![]() |
Re: Deleting chracters
Quote:
|
|
|
|
|
|
|
#5 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,004
Rep Power: 5
![]() |
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.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2008
Posts: 5
Rep Power: 0
![]() |
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'
|
|
|
|
|
|
#7 | ||
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,004
Rep Power: 5
![]() |
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 length jcxz L3 ; guard against zero-length string; if this is the case, exit mov si, string ; load the string start address mov al, 32 ; mem, reg operations are more efficient than mem, imm8 L1: cmp [si], byte 97 jb L2 ; go on to next iteration if [si] < 97, ie if it's < 'a' cmp [si], byte 122 ja L2 ; go on to next iteration if [si] > 122, ie if it's > 'z' sub [si], al L2: inc si ; point at next character loop L1 ; loop to process remaining characters L3: ; all done now The 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 length jcxz L2 ; guard against zero-length string; if this is the case, exit mov si, string ; load the string start address mov bx, table ; load the lookup table mov al, [si] ; fetch the first byte of the string and al, 07Fh ; limit it to ASCII range (0-127) xlatb ; transform it mov [si], al ; and write it back inc si loop L1 L2: ; all done now There 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:
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
||
|
|
|
|
|
#8 |
|
Newbie
Join Date: Mar 2008
Posts: 9
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#9 | ||
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,004
Rep Power: 5
![]() |
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.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Linked List problem - Deleting a node | Brent | C++ | 9 | Dec 16th, 2007 3:39 PM |
| Type Mismatch - Deleting Records | raikkonen | ASP | 1 | Nov 16th, 2005 6:00 AM |
| Deleting files through vbs in html | guzpapir | JavaScript and Client-Side Browser Scripting | 8 | Aug 27th, 2005 11:14 AM |
| copying files first before deleting them | harjit | Visual Basic | 1 | May 15th, 2005 7:05 AM |
| deleting files like evidence eliminator | linebacker | C++ | 10 | Apr 2nd, 2005 1:51 PM |