Cut string, js split string
First, blow the intention: cut the string because when the image address is saved in the database, a commodity may have multiple images. We can create a commodity table (goods) and an image table (goods_image), and then use the id of the image table as the foreign key of the commodity table to implement one-to-many Association.
However, if you want to create a table with a path and a path, there will be a lot of data. Since you can add a field (goods_image_url) to the product table, why not?
Next, let's talk about the idea: The image address is spliced together and then divided into a separate image address. In this case, a separator is used to separate each address before splicing. The split address can be received by using the List <String> set or the Arrays array.
So I wrote a tool class: StringToArrays
1 public class StringToArrays {2 3 String [] arrayStr; 4 6 public String [] staMethod (String str, String separator) {7 8 arrayStr = str. split (separator); // The split character is separator, and then the result is sent to array 9 return arrayStr; 10} 11}
As you can see, the code is actually very simple, that is, defining an array to receive the address value after being split. Then define a method. Since it is intended to be generic, two parameters must be input in the method. The first parameter is string data, and the second parameter is a separator. If someone else calls the parameter, I have to return a parsed string array.
The tool class has been written. When the Android end obtains the address value from the database, it calls the method of the tool class above to obtain the address array, then, you can know the length of the array through the length method of the array and other operations. Finally, you can display network images by loading some plug-ins or third-party tools.