简体   繁体   English

从一长串文本中提取数量(数字)

[英]Extracting quantity (number) from long string of text

The problem I'm having is this.我遇到的问题是这个。 The data I pull adds information in a very inconvenient way.我拉取的数据以一种非常不方便的方式添加信息。 When I'm trying to isolate and extract a certain text within the string it becomes super complicated.当我试图隔离和提取字符串中的某个文本时,它变得非常复杂。 I want to be able to extract the quantity of the product to show only the numerical value, no alpha text or characters.我希望能够提取产品的数量以仅显示数值,没有字母文本或字符。

The string is:字符串是:

[{"orderItemId":609507407,"lineItemKey":"1509870501993","sku":"SKU-111111","name":"Company Product - NA / Ships in 1-2 business days","imageUrl":" https://FAKEADDRESS.com/ ","weight":{"value":352.0,"units":"ounces","WeightUnits":1},"quantity":1,"unitPrice":1599.0,"taxAmount":null,"shippingAmount":null,"warehouseLocation":null,"options":[],"productId":30236912,"fulfillmentSku":null,"adjustment":false,"upc":"","createDate":"2018-11-03T20:20:42.247","modifyDate":"2018-11-03T20:20:42.247"}] [{"orderItemId":609507407,"lineItemKey":"1509870501993","sku":"SKU-111111","name":"公司产品 - NA / 1-2 个工作日内发货","imageUrl":" https://FAKEADDRESS.com/ ","weight":{"value":352.0,"units":"ounces","WeightUnits":1},"quantity":1,"unitPrice":1599.0,"taxAmount ":null,"shippingAmount":null,"warehouseLocation":null,"options":[],"productId":30236912,"fulfillmentSku":null,"adjustment":false,"upc":"","createDate ":"2018-11-03T20:20:42.247","修改日期":"2018-11-03T20:20:42.247"}]

Using (LEFT(RIGHT(N2:N,LEN(N2:N)-FIND("quantity",N2:N,1)-9),3)) I'm able to find the correct location of the quantity, however, if the numerical value (quantity) is 2 or 3 digits, it will keep whatever text/number follows.使用 (LEFT(RIGHT(N2:N,LEN(N2:N)-FIND("quantity",N2:N,1)-9),3)) 我能够找到数量的正确位置,但是, 如果数值(数量)是 2 或 3 位数字,它将保留后面的任何文本/数字。

ie "quantity":123 will show 123 but "quantity":1," will show 1,"即 "quantity":123 将显示 123 但 "quantity":1," 将显示 1,"

(LEFT(RIGHT(N2:N,LEN(N2:N)-FIND("quantity",N2:N,1)-9),3)) (左(右(N2:N,LEN(N2:N)-查找(“数量”,N2:N,1)-9),3))

Essentially, I just want the formula to show a number value (quantity) in the cell.本质上,我只想让公式在单元格中显示一个数值(数量)。 Nothing else.没有其他的。

That looks like JSON to me and even Regular Expression may be overkill for a single quantity integer.对我来说,这看起来像 JSON,甚至正则表达式对于单个数量的整数也可能是矫枉过正。

Dim str As String, el As String, q As Long

str = "[{""orderItemId"":609507407, ... ,""quantity"":1,""unitPrice"":1599.0, ... ,""modifyDate"":""2018-11-03T20:20:42.247""}]"
el = """quantity"":"

q = val(Mid(str, InStr(1, str, el) + Len(el)))
Debug.Print q

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM