Perhaps this has come up before but thought I would mention it, as it seems to be inconsistent behavior compared to some other functions. Given the following, searchinfo ends up being a blank string. While I can see the argument for that being the case, it seems like the value should end up being "HELLO". If you do a similar thing with ItemInsert, it has an ending value of "HELLO" rather than being a blank string.
Jim
cu = "HELLO"
searchinfo = ""
searchinfo = ItemReplace(cu, 1, searchinfo, "#")
Message("SI",searchinfo)
I've stared at this for 5 minutes, and I think I agree with you.
Maybe there might be some code out there that depends on this behavior? Its an edge case, the empty list, so... tough call.
So:
count=ItemCount(searchinfo, "#")
should return 1 (a blank string) but instead returns 0 which is why it cannot replace.
Likewise:
extract1=ItemExtract(1, searchinfo, "#")
should create an error, rather than extract1 being blank ("").
Perhaps documentation should address using "" as a delimiter, as some might think that flies in the face of a concept of a 'list'. This, however, does not remediate the previous posts which are valid.
I think ItemReplace works as I would expect. With ItemReplace you are specifying which item (index) to replace in the list.
An empty string list does not have an item 1 to replace so the empty string is maintained. Changing List to equal "#" makes it have two empty strings to work with and a replacement occurs.
With the first code example, you would either do List = "HELLO" or List = Replacement
This code made more sense to me...
No replacement occurs
Replacement = "HELLO"
Index = 1
List = ""
List = ItemReplace(Replacement, Index, List, "#")
Message("Replacement",List)
Replacement occurs
Replacement = "HELLO"
Index = 1
List = "#"
List = ItemReplace(Replacement, Index, List, "#")
Message("Replacement",List)
If you can replace a blank item because there are many, then you should be replace a blank item because there is 1.