Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substituting text

Status
Not open for further replies.

mtastad

Programmer
Feb 5, 2002
18
0
0
US
Does anyone know of a slick way to substitute text in a text field? I want to search for a specific set of characters and replace them with a different set of characters. Thanks!
 
It depends on several things. A CHANGETO query is the fastest way, IF the text and its replacement is consistant. Give us more details about the nature of the data.
Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
The data that I am using will be consistant. I want to have a database of generic part numbers that the user will pick options for (from a radio button). When the user chooses an option, the placeholder text (such as *M for material) in the generic part number will be replaced with the specific text (such as AL for aluminum) for that option. I think I can do this by first searching for the placeholder in the text string, then breaking the string into two strings (not including the placeholder) and then combining the two strings with the new text. I want to be able to have multiple paramaters that are changed in this way and am hoping that there is an easier way. Hope this additional information helps...
 
I still need to know one thing, are you going to change only the text of a single record, or are there multiple records containing that part number which have to be change? In other words:

M1234*
M3224
M6655
M1234*
M7895
M1234*

Would you need to change all three of the marked records, or just one of them if the user was dealing with part number M1234? Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
I will be changing a single record. When the user wants to add a new part# to the current quote, they will choose the generic part# from a drop-down list and click a button to insert it. I then copy the information from this generic part number to temp tables and open a form displaying only this information. The user then will choose from radio buttons the specifics for this part number and the part# text as well as the parts in the child tables will change accordingly. The user will then click a "done" button and the data will be copied from the temp tables into the tables for quotes.

We currently create part#'s in our part database that contain every different variety of options. It becomes difficult to maintain. I am trying to establish generic part#'s that contain only unique information for the manufactured components. I am hoping that I can then create an interface that will make it easy for the user to "fine tune" the part# with specifics and then bring it into a quote.

The only programming that I am struggling with (I haven't done much with string manipulations) is having the characters in the part number update as the user chooses options. Thanks for your patience with this and I look forward to any help you can provide - Mark
 
Well if you can supply a typical part number, then I can suggest some code. It sounds as though the piece of the string you want changed is in the middle. Since you said the numbers are consistant, I would assume you are doing something like: 4 chars, an M, and 4 more chars (1234M4321). If this is the case, then I would use substr() and do it like this, assuming the field on your form is called codeNum and the radio button is called usersChoice:

Code:
var
 tempCode  string
 newCode   string
endvar

tempCode = codeNum.value
newCode = usersChoice.value ;say 'AL' for example

codeNum.value = tempCode.substr(1,4)+newCode+tempCode.subStr(6,4)

This would convert 1234M4321 to 1234AL4321. You can see that this would not work if the numbers are of different lengths, but could easily be adapted if the 'M' is in a constant position, say always the 5th character. like this:

Code:
var
 tempCode  string
 newCode   string
endvar

tempCode = codeNum.value
newCode = usersChoice.value ;say 'AL' for example

codeNum.value = tempCode.substr(1,4)+newCode+tempCode.subStr(6,(tempCode.sizeEx()-5))


This would convert 1234M4321 to 1234AL4321, or 3344M443355 to 3344AL443355.

The most difficult way would be to find the M no matter what position it's in and replace it. That would entail using code similar to the above, but obtaining the position number of the M using a short custom method that returned the number position. Of course error trapping would have to be added to prevent a blank value (or value without an M) from being processed. I can cobble together an example for that if you need it. Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Just in case I don't get back on here, here is the code for the short method (called whereAmI()) and the code to change the number in the event that the M is randomly placed in the part number. Again, this was tested with two blank fields named codeNum and usersChoice.

Code:
method whereAmI(inVar string) number
var
	counter, position, nullFlag, fullSize	number
endvar

position = 0
nullFlag = 0
counter  = 1

if inVar = ""	then	return position endif

fullSize = inVar.sizeEx()

while	counter <= fullSize

	if upper(inVar.substr(counter,1)) = &quot;M&quot;
   	then	position = counter
      		quitLoop
   endif
	counter = counter+1

endWhile

if position = fullsize
	then	return 9999 ; last position
   	else	return position
endif

endMethod

and the change code

Code:
var
 tempCode  string
 newCode   string
 location  number
endvar

tempCode = codeNum.value
location = whereAmI(tempCode)
if location = 0
	then	msgStop(&quot;Error&quot;,&quot;Invalid part number&quot;)
			return
endif


newCode = usersChoice.value ;say 'AL' for example

if location = 9999
	then	codeNum.value = tempCode.subStr(1,(tempCode.sizeEx()-1))+newCode
   		return
endif

if location = 1
	then	codeNum.value = newCode+tempCode.subStr(2,(tempCode.sizeEx()-1))
   	else codeNum.value = tempCode.substr(1,location-1)+newCode+tempCode.subStr(location+1,(tempCode.sizeEx()-(location-1)))
endif

Hope this works for you.

Mac :)

&quot;There are only 10 kinds of people in this world... those who understand binary and those who don't&quot;

langley_mckelvy@cd4.co.harris.tx.us
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top