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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Characters in String to Value(s) 2

Status
Not open for further replies.

alembong

Technical User
Feb 16, 2005
18
US
CR XIr2

I have a string field where each character (case-sensitive) equals a type of action. I want to replace the character with the appropriate action type.

I've tried the Replace function, but I'm not sure how to do multiple characters all at once. I tried nesting, but it would replace values in the replaceString

I also tried creating an array formula that would split then case the values using a for loop, but the string has no delimiter. (This was based on an answer given by LBass to split a string)

Here's some sample data:
User Action
Bob "aCduv"
Sam "pvVs"

I'd like it to be:
Bob "add create delete update view"
Sam "process view verify schedule"

Any help would be appreciated!
 
OK before I start .... most people think my code is wierd and it probably is but it usually works for me! :D
.....
to get Action "aCduv" to read " add create delete update view"
formula:
Code:
local stringvar stroutput := "";
local Numbervar strLen :=
    Length({table.action});
local numbervar i;
For i := 1 to strLen Do
(
    Local NumberVar charpos := strLen - i +1;
    if ({table.action}[charpos] = "a" then
        stroutput := stroutput + " add "
    else if ({table.action}[charpos] = "C" then
        stroutput := stroutput + " create "
    else if ({table.action}[charpos] = "d" then
        stroutput := stroutput + " delete "
    else if ({table.action}[charpos] = "u" then
        stroutput := stroutput + " update "
    else if ({table.action}[charpos] = "v" then
        stroutput := stroutput + " View "


);
stroutput
add additional else if statements for all the possibilities
 
you might throw this as the last else to make sure you know when there is a new action or one that you havent coded yet
Code:
else stroutput := stroutput + " ??? "
 
whups ... thats what I get for copying code i used for something else rather than writing it new....

sorry

change the line that reads ....
Local NumberVar charpos := strLen - i +1;
to
Local NumberVar charpos := i;
otherwise your output comes backwards.
 
Thanks! This does exactly what I was wanting it to do. Doesn't really matter if people think it's weird as long as it works! :eek:)
 
I think I may need to re-visit this code because I think that it is not taking into account the character case.

Is there a way that I can change it so that it is case-sensitive when it goes through the if statements?
 
I think I may have figured it out by using the InStr function which is by default case sensitive.

Code:
local stringvar stroutput := "";
local Numbervar strLen :=
    Length({table.action});
local numbervar i;
For i := 1 to strLen Do
(
    Local NumberVar charpos := i;
    if InStr({table.action}[charpos],"p") > 0 then
        stroutput := stroutput + " process"
    else if InStr({table.action}[charpos],"v") > 0 then
        stroutput := stroutput + " view"
    else if InStr({table.action}[charpos],"V") > 0 then
        stroutput := stroutput + " verify"
    else if InStr({table.action}[charpos],"s") > 0 then
        stroutput := stroutput + " schedule"
);
stroutput
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top